通俗易懂暴力法最简真分数
最简真分数
http://www.nowcoder.com/questionTerminal/1f1db273eeb745c6ac83e91ff14d2ec9
#include <iostream> #include <cstdio> using namespace std; int n[601]; int GCD(int a, int b) { if (b == 0) { return a; } else { return GCD(b, a % b); } } int main() { int num; while (scanf("%d", &num) != EOF) { int number = 0; if (num == 0) { break; } for (int i = 0; i < num; ++i) { scanf("%d", &n[i]); } for (int i = 0; i < num; ++i) { for (int j = 0; j < num; ++j) { if (n[i] < n[j]) { if (GCD(n[i], n[j]) == 1) { number++; } } } } printf("%d\n", number); } return 0; }