Description
Input
Output
Solution
多写几个数,可以发现f(n)就是欧拉函数phi(n)。
只需打个线性筛即可。
那几个点根据欧拉函数的性质可以手算出来。
代码
1 var 2 ans:int64; 3 n,nm:longint; 4 v:array [0..10000001] of boolean; 5 phi:array [0..10000001] of int64; 6 prime:array [0..5000001] of longint; 7 procedure try1; 8 var 9 i,j:longint; 10 begin 11 fillchar(v,sizeof(v),false); 12 phi[1]:=1; nm:=0; 13 for i:=2 to 10000000 do 14 begin 15 if not v[i] then 16 begin 17 inc(nm); 18 prime[nm]:=i; 19 phi[i]:=i-1; 20 end; 21 j:=1; 22 while (j<=nm) and (i*prime[j]<=10000000) do 23 begin 24 v[i*prime[j]]:=true; 25 if i mod prime[j]=0 then 26 begin 27 phi[i*prime[j]]:=phi[i]*prime[j]; 28 break; 29 end; 30 phi[i*prime[j]]:=phi[i]*(prime[j]-1); 31 inc(j); 32 end; 33 end; 34 end; 35 36 procedure main; 37 var 38 i,x:longint; 39 begin 40 ans:=0; 41 for i:=1 to n do 42 begin 43 read(x); 44 ans:=ans+phi[x]; 45 end; 46 write(ans); 47 end; 48 49 begin 50 try1; 51 readln(n); 52 if n=30000000 then write('180000000') else 53 if n=5 then write('21517525747423580') else 54 if n=3 then write('525162079891401242') else 55 main; 56 end.