BZOJ4407

http://www.lydsy.com/JudgeOnline/problem.php?id=4407

#include
typedef long long ll;
const int N=5e6+11,maxn=5e6,mod=1e9+7;
bool ip[N];
int pr[N/20];
int k,p1,p2;
ll sum[N],f[N];
ll ans;
inline ll fp(ll a,int b){
    ll ret=1;
    while(b){
        if(b&1)ret=ret*a%mod; 
        a=a*a%mod;
        b>>=1;
    } 
    return ret;
} 
inline void shai_fa(){
    f[1]=1ll;
    for(register int i=2,l,p;i<=maxn;++i){
        if(!ip[i]){
            pr[++pr[0]]=i;
            f[i]=1ll*(fp(1ll*i,k)-1+mod)%mod;
        }
        for(register int j=1;j<=pr[0]&&i*pr[j]<=maxn;++j){
            ip[pr[j]*i]=1;
            if(i%pr[j]==0){ 
                l=i;
                p=pr[j];
                while(l%pr[j]==0){
                    l/=pr[j];
                    p*=pr[j];
                }
                if(l!=1){
                    f[l*p]=1ll*f[l]*f[p]%mod;
                    break;
                }
                p1=fp(1ll*i*pr[j],k);
                p2=fp(1ll*i,k);
                f[i*pr[j]]=1ll*(p1-p2+mod)%mod;
                break;
            } 
            f[i*pr[j]]=1ll*f[i]*f[pr[j]]%mod;
        }
    }
    for(register int i=1;i<=maxn;++i){
    	f[i]+=f[i-1];
    	f[i]%=mod;
	}
}
int n,m,T,pos;
inline int min(int a,int b){return a

  

转载于:https://www.cnblogs.com/Stump/p/8037704.html

你可能感兴趣的:(BZOJ4407)