The Euler function
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4559 Accepted Submission (s): 1902
Problem DescriptionThe Euler function phi is a important kind of function in number theory, (n) represents the amount of The numbers which is smaller than N and coprime to n, and this function have a lot of beautiful characteristics. Here comes a very easy question:suppose is given a, B, try to calculate (a) + (a+1) +....+ (b)
Inputthere is several test cases. Each line has a integers a, b (2<a<b<3000000).
Outputoutput The result of (a) + (a+1) +....+ (b)
Sample INPUT3 100
Sample Output3042
Source2009 multi-university Training Contest 1-host by Tju
Recommendgaojie | We have carefully selected several similar problems for you:2818 2825 2817 2822 2821
#include <cstdio>#include<cstring>#include<iostream>using namespacestd;Const intN =3000010;intPrime[n], isprime[n];intPhi[n];voidGet_phi () {intI, j, cnt =0; for(i =2; i < N; i++){ if(Isprime[i] = =0) {prime[cnt++] =i; Phi[i]= I1; } for(j =0; J < CNT && I*prime[j] < N; J + +) {Isprime[i*prime[j]]=1; if(i%prime[j]==0) Phi[i*prime[j]]=phi[i]*Prime[j]; ElsePhi[i*prime[j]]=phi[i]* (prime[j]-1); } } } intMain () {intA, B; Get_phi (); while(~SCANF ("%d%d", &a, &b)) {Long Longsum =0; for(inti = A; I <= b; i++) Sum+=Phi[i]; cout<< sum <<Endl; } return 0;}
Hangzhou Electric 2824--the Euler function (Euler functions)