# The Euler function

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5502    Accepted Submission(s): 2326

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)

Sample Input
3 100

Sample Output
3042

Source

1、素数p的欧拉函数是p-1，即 φ（p）=p-1。特别地，φ（1）=1。
2、p的k次方的欧拉函数是（p-1）*p的k-1次方，即 φ（p^k)=(p-1)*p^(k-1)。
3、积性函数， φ（mn）=φ(m)*φ(n)
4、埃式筛法（快速寻找n以内的质数）和质因数分解 （埃式筛法和质因数分解还有欧拉函数模板等内容请详情查看另一篇文章。）

``````#include<iostream>
#include<cstdio>
using namespace std;

int phi[3000000];
int dive[3000000];

int main()
{
int a,b;
while(cin>>a>>b)
{
long long sum=0;
for(int i=1;i<=b;i++)
{
phi[i]=i;
}
for(int i=2;i*i<=b;++i)
{
if(phi[i]==i)
{
for(int j=i*i;j<=b;j+=i)
{
phi[j]=i;
}
}
}
dive[1]=1;
for(int i=2;i<=b;++i)
{
dive[i]=dive[i/phi[i]];
if((i/phi[i])%phi[i]==0)
{
dive[i]*=phi[i];
}
else
{
dive[i]*=phi[i]-1;
}
}
for(int i=a;i<=b;i++)
{
sum+=1LL*dive[i];
}
cout<<sum<<endl;

}
}``````