题意:http://www.lightoj.com/volume_showproblem.php?problem=1007
求[a,b]范围内所有整数的欧拉函数的平方和。欧拉函数:求不大于其本身的与其互质的数的个数。
第一次用这个 结果会爆long long,要用unsigned long long %llu形式;
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<queue> #include<map> #include<vector> #include<math.h> #include<string> using namespace std; #define INF 0x3f3f3f3f typedef unsigned long long LL; #define N 5000006 #define Lson rood<<1 #define Rson rood<<1|1 LL sum[N]; int a[N]; void Eular() { for(int i=2;i<N;i++) { if(!a[i]) { for(int j=i;j<N;j+=i) { if(a[j]==0) a[j]=j; a[j]-=a[j]/i; } } } for(int i=1;i<N;i++) sum[i]=sum[i-1]+(LL)a[i]*a[i]; } int main() { Eular(); int T,t=1; scanf("%d",&T); while(T--) { int e,f; scanf("%d%d",&e,&f); printf("Case %d: %llu ",t++,sum[f]-sum[e-1]); } return 0; }