UVa11417

題目:
https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=26&page=show_problem&problem=2412

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <cmath>

using namespace std;

int gcd(int x, int y){
if(x % y == 0) return y;
else return gcd(y, x%y);
}

int main(){
int n, g;
while(cin >> n){
if(n == 0) break;
g = 0;
for(int i=1; i<n; ++i){
for(int j=i+1; j<=n; ++j){
g += gcd(i, j);
}
}
cout << g << '\n';
}
return 0;
}