标签:style class blog c code tar
欧拉函数。
结果一定用unsigned long long。
1 //Accepted 40148 KB 712 ms 2 #include <cstdio> 3 #include <cstring> 4 const int MAXN = 5000005; 5 unsigned long long phi[MAXN]; 6 void getphi() 7 { 8 phi[1]=0; 9 for (int i=2;i<MAXN;i++) 10 { 11 if (!phi[i]) 12 { 13 for (int j=i;j<MAXN;j+=i) 14 { 15 if (!phi[j]) 16 { 17 phi[j]=j; 18 } 19 phi[j]=phi[j]/i*(i-1); 20 } 21 } 22 } 23 for (int i=2;i<MAXN;i++) 24 phi[i]=phi[i-1]+phi[i]*phi[i]; 25 } 26 int main() 27 { 28 getphi(); 29 int T; 30 scanf("%d",&T); 31 int a,b; 32 for (int t=1;t<=T;t++) 33 { 34 scanf("%d%d",&a,&b); 35 if (a>b) 36 { 37 t=a; 38 a=b; 39 b=t; 40 } 41 printf("Case %d: %llu\n",t,phi[b]-phi[a-1]); 42 } 43 return 0; 44 }
lightoj1007Mathematically Hard,布布扣,bubuko.com
lightoj1007Mathematically Hard
标签:style class blog c code tar
原文地址:http://www.cnblogs.com/djingjing/p/3751152.html