xtu oj 1355
作者:互联网
include<stdio.h>
#define N 3000005
int z[N]={0};//0是质数
__int64 phi[N]={0};
__int64 sum[N]={0};
int main( )
{
__int64 i,j;
z[1]=1;
for(i=2;i<=N;i++)
{
for(j=i*i;j<=N;j+=i)
{
z[j]=1;
}
}
phi[1]=1;
for(i=2;i<=N;i++)
{
if(z[i]==1)
{
phi[i]=i;
}
else
{
phi[i]=i-1;
}
}
// printf("=-=%d\n",z[2]);
// printf("%I64d\n",phi[2]);
for(i=2;i<=N;i++)
{
if(z[i]==0)
{
for(j=2;j*i<=N;j++)
{
phi[i*j]=phi[i*j]*phi[i]/i;
}
}
}
// printf("%I64d\n",phi[2]);
for(i=1;i<=N;i++)
{
sum[i]=sum[i-1]+phi[i];
}
int T;
// printf("%I64d\n",phi[2]);
scanf("%d",&T);
while(T--)
{
int a,b;
scanf("%d%d",&a,&b);
printf("%I64d\n",sum[b]-sum[a]+phi[a]);
}
}
Memory: 59980K Time: 968MS
Language: G++ Result: Accepted
标签:__,phi,oj,int,sum,xtu,1355,printf,I64d 来源: https://blog.csdn.net/TheShine912/article/details/111059494