题解 | #最简真分数#
最简真分数
https://www.nowcoder.com/practice/1f1db273eeb745c6ac83e91ff14d2ec9
#include <stdio.h> int a[610]; //求最大公因数 int gcd(int a, int b){ if(b == 0) return a; return gcd(b, a % b); } int main() { int count; int n; while (scanf("%d", &n) != EOF & n != 0) { count = 0; for(int i = 0; i < n; i ++) scanf("%d", &a[i]); for(int i = 0; i < n; i ++){ for(int j = i + 1; j < n; j ++){ if(gcd(a[i], a[j]) == 1)//最大公因数=1,说明两者没有公因数 count ++; } } printf("%d\n", count); } return 0; }