文章
211
粉丝
1
获赞
1146
访问
40.2k
//分子小于分母且分子与分母没有其他公因数的分数
#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;
}
登录后发布评论
暂无评论,来抢沙发