簡單 時間限制:3 s記憶體限制:256 MB

Online Judge - 11417 - GCD

來源代碼:UVa
數學枚舉CPE歷屆試題CPE一星
前往提交 ↓

Given the value of N, you will have to find the value of G. The definition of G is given below:

G =\sum_{i=1}^{i<N} \sum_{j=i+1}^{j≤N} GCD(i, j)

Here GCD(i, j) means the greatest common divisor of integer i and integer j. For those who have trouble understanding summation notation, the meaning of G is given in the following code:

G=0;
for(i=1;i<N;i++)
for(j=i+1;j<=N;j++)
{
    G+=GCD(i,j);
}
/*Here GCD() is a function that finds
the greatest common divisor of the two
input numbers*/

輸入說明

The input file contains at most 100 lines of inputs. Each line contains an integer N (1 < N < 501). The meaning of N is given in the problem statement. Input is terminated by a line containing a single zero. This zero should not be processed.

輸出說明

資料格式說明

For each line of input produce one line of output. This line contains the value of G for corresponding N.

輸入輸出範例

範例 1

範例輸入
10
100
500
0
範例輸出
67
13015
442011

範例 2

範例輸入
2
3
0
範例輸出
1
3

範例 3

範例輸入
6
4
6
0
範例輸出
20
7
20
開啟討論
開啟紀錄

登入後即可撰寫程式、測試範例及提交解答。

登入