题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=3e6;
int phi[N+3];
void init()
{
for(int i=1;i<=N;i++)
phi[i]=i;
for(int i=2;i<=N;i++)
{
if(phi[i]==i)
{
for(int j=i;j<=N;j+=i)
phi[j]=phi[j]/i*(i-1);//i是j的质因子
}
}
}
int main()
{
int a,b;
init();
while(~scanf("%d%d",&a,&b))
{
ll ans=0;
for(int i=a;i<=b;i++)
ans+=phi[i];
printf("%lld\n",ans);
}
return 0;
}