文章

211

粉丝

1

获赞

1146

访问

40.2k

头像
最简真分数 题解:
P1180 北京大学/北京航空航天大学机试题
发布于2026年2月5日 15:17
阅读数 176

//分子小于分母且分子与分母没有其他公因数的分数
#include<bits/stdc++.h>
using namespace std;

int gcd(int x, int y) { //求最大公约数
	return y == 0 ? x : gcd(y, x % y); 
}
int main() {
    int n;
    while (cin >> n) {
        vector<int> a(n);
        for (int i = 0; i < n; i++) 
			cin >> a[i];
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) 
					continue;
                if (a[i] < a[j] && gcd(a[i], a[j]) == 1) {
                    cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发