您的位置:首页 > 其它

hdu 2824 The Euler function 欧拉函数模板题

2013-09-13 19:49 204 查看
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL __int64
const LL maxn=3e6+10;
LL phi[maxn+10];
void phi_table()//求欧拉函数
{
    LL i,j,k;
    for(i=2;i<maxn;i++)phi[i]=0;
    phi[1]=1;
    for(i=2;i<maxn;i++)
    {
        if(!phi[i])
        for(j=i;j<=maxn;j+=i)
        {
            if(!phi[j])phi[j]=j;
            phi[j]=phi[j]/i*(i-1);
        }
        phi[i]+=phi[i-1];
    }
}
int main()
{
    LL a,b;
    phi_table();
    while(cin>>a>>b)
    {
        cout<<phi[b]-phi[a-1]<<endl;
    }
    return 0;
}
/*
    phi[i]表示前i个欧拉函数的和。
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: