题目大意:关于最大公约数(Greatest Common Divisor, GCD)的,直接照着题目说的做就可以了。
1 #include2 3 int gcd(int a, int b) 4 { 5 return b == 0 ? a : gcd(b, a%b); 6 } 7 8 int main() 9 {10 int n;11 while (scanf("%d", &n) && n)12 {13 int g = 0;14 for (int i = 1; i < n; i++)15 for (int j = i+1; j <= n; j++)16 g += gcd(j, i);17 printf("%d\n", g);18 }19 return 0;20 }