Konjac is really too residue of ...... especially math portion abuse many chiefs residue left ......
So today I work hard konjac decision charged the math! Review the Euler function first ...... / paste face / paste face
Euler function definition: 1 ~ N N and the number of prime numbers is called the Euler function, referred to as φ (N).
Euler function general formula: φ (N) =
Proof: Let p be prime factors N, multiples of 1 ~ N in a total of N p / p number,
Similarly, if N q is the quality factor, N is a multiple of q 1 ~ N are / q th.
If we / p and N / N to remove this number q, where q is a common multiple of p is excluded twice, to add back.
Therefore, the number of 1 ~ N in number N does not contain a common prime factors p or q is: N * (1-1 / p) (1-1 / q)
(More than prove that uses the inclusion-exclusion principle)
QED.
Road to the template title
题目大意:给出一段区间,求出这段区间的所有数的欧拉函数值和。
#include<cstdio>
#include<cstring>
using namespace std;
int phi[3000003];
int main()
{
int a,b;
long long ans=0;
while(scanf("%d %d",&a,&b)!=EOF)
{
ans=0;
for(int i=2;i<=b;++i)
phi[i]=i;
for(int i=2;i<=b;++i)
if(phi[i]==i)
for(int j=i;j<=b;j+=i)
phi[j]=phi[j]/i*(i-1);
for(int i=a;i<=b;++i)
ans+=(long long)phi[i];
printf("%lld\n",ans);
}
return 0;
}