文章

81

粉丝

2

获赞

508

访问

10.3k

头像
最简真分数 题解:
P1180 北京大学/北京航空航天大学机试题
发布于2026年3月12日 22:06
阅读数 158

#include <iostream>
#include <algorithm>
using namespace std;

int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main(){
    int n;
    while(cin >> n){
        int a[605];
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }

        sort(a, a + n);

        int count = 0;
        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n; j++){
                if(gcd(a[i], a[j]) == 1){
                    count++;
                }
            }
        }

        cout << count << endl;
    }
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发