//求a , b范围内的所有的欧拉函数
//筛选法求欧拉函数模板题
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std ;
const int maxn = 3000010 ;
typedef __int64 ll ;
int e[maxn] ;
int a , b ;
void Euler()
{
int i,j;
for (i=1;i<maxn;i++) e[i]=i;
for (i=2;i<maxn;i++)
if (e[i]==i) // 当e[i] == i时,可以发现i即为素数
{
e[i]=i-1;
for (j=i*2;j<maxn;j+=i) e[j]=e[j]/i*(i-1);
}
}
int main()
{
Euler() ;
while(~scanf("%d%d" , &a , &b))
{
ll ans = 0 ;
for(int i = a ;i <= b;i++)
ans += (ll)e[i] ;
printf("%I64d\n" , ans) ;
}
return 0 ;
}
时间: 2024-08-02 06:54:31