Given the value of N, you will have to find the value of G. The definition of G isgivenbelow:
>G=∑i=1n−1∑j=i+1NGCD(i,j)>
>
G
=
∑
i
=
1
n
−
1
∑
j
=
i
+
1
N
G
C
D
(
i
,
j
)
>
Here GCD(i, j) means the greatest common divisor ofinteger i andinteger j.
For those who have trouble understanding summation notation, the meaning of G isgiveninthe 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 findsthe greatest common divisor ofthe two input
numbers*/
【Input】
The input file containsat most 100linesof inputs. Each linecontainsaninteger N
(1 < N < 4000001).
The meaning of N is given inthe problem statement. Input is terminated byaline
containing a single zero.
【Output】
For eachlineof input produce onelineof output. This linecontainsthevalueof
G forthe corresponding
N. The valueof G will fit ina64-bit signed integer.
【Examples】
Sample Input
10
100
200000
0
Sample Output
67
13015
143295493160
【Problem Description】
题意就一个式子。不用多说。
【Solution】
数论。欧拉函数。
对于题目给的式子不太好求,我们将其转换一下。转换为以下形式:
>G=∑i=2N∑j=1i−1GCD(j,i)>
>
G
=
∑
i
=
2
N
∑
j
=
1
i
−
1
G
C
D
(
j
,
i
)
>
UVA-11426-GCD - Extreme (II)-数论-欧拉函数【Description】 Given the value of N, you will have to find the value of G. The definition of G isgiven below: &gt;G=∑i=1n−1∑j=i+1NGCD(i,j)&gt;&gt;G=∑i=1n...