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
#include<stdio.h>
#define MAX_N 3000100
int phi[MAX_N];
void init(){
for(int i=1;i<MAX_N;i++) phi[i]=i;
for(int i=2;i<MAX_N;i++)
if(phi[i]==i)
for(int j=i;j<MAX_N;j+=i)
phi[j]=phi[j]/i*(i-1);
}
int main()
{
init();int a,b;
while(~scanf("%d%d",&a,&b)){
long long ans=0;
for(int i=a;i<=b;i++)
ans+=phi[i];
printf("%lld\n",ans);
}
return 0;
}