• 杜教筛入门


    https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1239

    51nod 1239

    欧拉函数之和

    #include<cstdio>
    #include<map>
    const int N=10000011,maxn=10000000;
    const int mod=1e9+7;
    typedef long long ll;
    std::map<ll,ll>mp;
    int pr[N];
    bool ip[N];
    int phi[N];
    int sum[N];
    inline void shai_fa(){
    	phi[1]=1ll;
    	for(register int i=2;i<=maxn;++i){
    		if(!ip[i])
    			phi[pr[++pr[0]]=i]=i-1;
    		for(register int j=1;j<=pr[0]&&pr[j]*i<=maxn;++j){
    			ip[i*pr[j]]=1;
    			if(i%pr[j]==0){
    				phi[i*pr[j]]=pr[j]*phi[i];
    				break;
    			}
    			phi[i*pr[j]]=phi[i]*phi[pr[j]];
    		}
    	}
    	for(register int i=1;i<=maxn;++i)
    		sum[i]=(sum[i-1]+phi[i])%mod;
    }
    ll T,n;
    inline ll query(ll x){
    	if(x<=maxn)return sum[x];
    	if(mp[x])return mp[x];
    	ll ans=1ll*x%mod*(x%mod+1)/2;
    	ll pos;
    	for(register ll i=2;i<=x;i=pos+1){
    		pos=x/(x/i);
    		ans-=1ll*(pos-i+1)*query(x/i)%mod;
    		ans=(ans+mod)%mod;
    	}
    	return mp[x]=ans;
    }
    int main(){
    	shai_fa();
    	scanf("%lld",&n);
    	printf("%lld
    ",query(n));
    	return 0;
    }
    

      

    https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244

    51nod 1244

    莫比乌斯函数之和

    #include<cstdio>
    #include<map>
    const int N=10000011,maxn=10000000;
    const int mod=1e9+7;
    typedef long long ll;
    std::map<ll,ll>mp;
    std::map<ll,bool>vis;
    int pr[N];
    bool ip[N];
    int miu[N];
    inline void shai_fa(){
    	miu[1]=1;
    	for(register int i=2;i<=maxn;++i){
    		if(!ip[i])
    			miu[pr[++pr[0]]=i]=-1;
    		for(register int j=1;j<=pr[0]&&pr[j]*i<=maxn;++j){
    			ip[i*pr[j]]=1;
    			if(i%pr[j]==0)
    				break;
    			miu[i*pr[j]]=-miu[i];
    		}
    	}
    	for(register int i=1;i<=maxn;++i)
    		miu[i]=(miu[i-1]+miu[i])%mod;
    }
    ll a,b;
    inline ll query(ll x){
    	if(x<=maxn)return miu[x];
    	if(vis[x])return mp[x];
    	ll ans=1,pos;
    	for(ll i=2;i<=x;i=pos+1){
    		pos=x/(x/i);
    		ans-=1ll*(pos-i+1)*query(x/i);
    	}
    	vis[x]=1;
    	return mp[x]=ans;
    }
    int main(){
    	shai_fa();
    	scanf("%lld%lld",&a,&b);
    	printf("%lld
    ",query(b)-query(a-1));
    	return 0;
    }
    

      

  • 相关阅读:
    转:超实用!聊聊图标设计流程及小技巧
    WPF 高性能画心电图
    转:WPF .NET 4.0下实现外发光效果
    (转)翻译:使用ViewModel模式来简化WPF的TreeView
    (转)How to get TreeViewItem from HierarchicalDataTemplate item?
    (转)WPF中的TreeView入门
    (转) WPF Treeview 学习 图标,checkbox,右键菜单
    linux中的定时任务--cron任务
    tar命令的使用与学习
    linux学习一
  • 原文地址:https://www.cnblogs.com/Stump/p/8040087.html
Copyright © 2020-2023  润新知