Given the value of N, you'll have the. nd the value of G. The de?nition of G is given below:
G =
I<n
∑
I=1
J
∑
≤n
J=i+1
GCD (i, J)
Here GCD (i, j) means the greatest common divisor of integer i and integer J.
For those who has 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
Input numbers*/
Input
The input Le contains at most lines of inputs. Each line contains an integer N (1 < N < 4000001).
The meaning of N is given in the problem statement. Input is terminated by a line containing a single
Zero.
Output
For each line of input produce one line of output. This line contains the value of G for the corresponding
N. The value of G would? t in a 64-bit signed integer.
Sample Input
10
100
200000
0
Sample Output
67
13015
143295493160
Test Instructions : Give n, Beg ∑ (i!=j) gcd (i,j) ( 1<=i,j<=n)
The following:s (n) =s (n-1) +gcd (1,n) +gcd (2,n) +......+GCD (n-1,n);
Set f (n) =gcd (1,n) +gcd (2,n) +......+GCD (n-1,n).
GCD (X,n) =i is an approximate (x<n) of N, classified according to this approximate. A constraint that satisfies the GCD (x,n) =i has g (n,i), then f (n) =sum (I*g (n,i)).
The GCD (x,n) =i is equivalent to gcd (x/i,n/i) = 1, so g (n,i) is equivalent to Phi (n/i). Phi (x) is an Euler function.
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespacestd; typedefLong Longll;Const intn=4000000+Ten; ll Phi[n+5], f[n+5];voidphi_table () { for(inti =2; I <= N; i++) Phi[i] =0; phi[1] =1; for(inti =2; I <= N; i++) { if(!Phi[i]) { for(intj = i; J <= N; J + =i) {if(!phi[j]) phi[j] =J; PHI[J]= Phi[j]/I * (i-1); }}}}ll S[n+5],n;intMain () {phi_table (); for(inti =1; I <= N; i++) { for(intj = i + i; J <= N; J + =i) {f[j]+ = i * phi[j/i]; } } for(inti =1; I <= N; i++) S[i] = s[i-1] +F[i]; while(~SCANF ("%lld",&N)) {if(!n) Break; printf ("%lld\n", S[n]); } return 0;}
Code
UVA 11426-gcd-extreme (II) Euler function-Mathematics