Problem Description The Euler function phi is an important kind of
function in number theory, (n) represents the amount of the numbers
which are smaller than n and coprime to n, and this function has a lot
of beautiful characteristics. Here comes a very easy question: suppose
you are given a, b, try to calculate (a)+ (a+1)+….+ (b)Input There are several test cases. Each line has two integers a, b (2 < a < b < 3000000).
Output Output the result of (a)+ (a+1)+….+ (b)
欧拉函数模板题。
注意开long long。
丧心病狂卡内存。
#include<cstdio>
#include<cstring>
const int n=3000000;
long long f[n+5];
void make()
{
int i,j,k,x,y,z;
f[1]=1;
for (i=2;i<=n;i++)
if (!f[i])
for (j=i;j<=n;j+=i)
{
if (!f[j]) f[j]=j;
f[j]=f[j]/i*(i-1);
}
for (i=1;i<=n;i++)
f[i]+=f[i-1];
}
int main()
{
int x,y;
make();
while (scanf("%d%d",&x,&y)==2)
printf("%lld\n",f[y]-f[x-1]);
}