• bzoj4176. Lucas的数论 杜教筛


    题意:求(sum_{i=1}^nsum_{j=1}^nd(ij),d是约数个数函数)
    题解:首先有一个结论(d(ij)=sum_{x|i}sum_{y|j}[(i,j)==1])
    那么(sum_{i=1}^nsum_{j=1}^nsum_{x|i}sum_{y|j}sum_{d|(i,j)}mu(d))
    枚举d,(sum_{i=1}^nsum_{j=1}^nsum_{d|i,d|j}mu(d)d(frac{i}{d})d(frac{j}{d})=sum_{d=1}^nmu(d)sum_{d|i}sum_{d|j}d(frac{i}{d})d(frac{j}{d})=sum_{d=1}^nmu(d)sum_{i=1}^{lfloor frac{n}{d} floor}d(i)sum_{j=1}^{lfloor frac{n}{d} floor}d(j))
    这里我们需要分块求(mu)(d)的前缀和,(mu)很好求,对于d,我们考虑(d=I*I),考虑把杜教筛中的(g(x)=mu),(I*I*mu=I*e=e),那么(S(n)=sum_{i=1}^n1-sum_{d=2}mu(d)S(lfloor frac{n}{d} floor))

    //#pragma GCC optimize(2)
    //#pragma GCC optimize(3)
    //#pragma GCC optimize(4)
    //#pragma GCC optimize("unroll-loops")
    //#pragma comment(linker, "/stack:200000000")
    //#pragma GCC optimize("Ofast,no-stack-protector")
    //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include<bits/stdc++.h>
    #define fi first
    #define se second
    #define db double
    #define mp make_pair
    #define pb push_back
    #define pi acos(-1.0)
    #define ll long long
    #define vi vector<int>
    #define mod 1000000007
    #define ld long double
    #define C 0.5772156649
    #define ls l,m,rt<<1
    #define rs m+1,r,rt<<1|1
    #define pll pair<ll,ll>
    #define pil pair<int,ll>
    #define pli pair<ll,int>
    #define pii pair<int,int>
    //#define cd complex<double>
    #define ull unsigned long long
    #define base 1000000000000000000
    #define Max(a,b) ((a)>(b)?(a):(b))
    #define Min(a,b) ((a)<(b)?(a):(b))
    #define fin freopen("a.txt","r",stdin)
    #define fout freopen("a.txt","w",stdout)
    #define fio ios::sync_with_stdio(false);cin.tie(0)
    template<typename T>
    inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
    template<typename T>
    inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
    inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
    inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
    inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
    inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
    inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}
    
    using namespace std;
    
    const double eps=1e-8;
    const ll INF=0x3f3f3f3f3f3f3f3f;
    const int N=5000000+10,maxn=3000000+10,inf=0x3f3f3f3f;
    
    int prime[N],cnt;
    ll d[N],num[N],mu[N];
    bool mark[N];
    map<ll,ll>dd,muu;
    void init()
    {
        mu[1]=d[1]=1;
        for(int i=2;i<N;i++)
        {
            if(!mark[i])prime[++cnt]=i,mu[i]=-1,d[i]=2,num[i]=1;
            for(int j=1;j<=cnt&&i*prime[j]<N;j++)
            {
                mark[i*prime[j]]=1;
                if(i%prime[j]==0)
                {
                    mu[i*prime[j]]=0;
                    num[i*prime[j]]=num[i]+1;
                    d[i*prime[j]]=d[i]/num[i*prime[j]]*(num[i*prime[j]]+1);
                    break;
                }
                mu[i*prime[j]]=-mu[i];
                d[i*prime[j]]=d[i]<<1;
                num[i*prime[j]]=1;
            }
        }
        for(ll i=1;i<N;i++)
        {
            add(d[i],d[i-1]);
            mu[i]=(mu[i]+mod)%mod;
            add(mu[i],mu[i-1]);
        }
    }
    ll getmu(ll n)
    {
        if(n<N)return mu[n];
        if(muu.find(n)!=muu.end())return muu[n];
        ll ans=1;
        for(ll i=2,j;i<=n;i=j+1)
        {
            j=n/(n/i);
            ll te=(j-i+1)%mod;
            sub(ans,te*getmu(n/i)%mod);
        }
        return muu[n]=ans;
    }
    ll getd(ll n)
    {
        if(n<N)return d[n];
        if(dd.find(n)!=dd.end())return dd[n];
        ll ans=n%mod;
        for(ll i=2,j;i<=n;i=j+1)
        {
            j=n/(n/i);
            ll te=(getmu(j)-getmu(i-1)+mod)%mod;
            sub(ans,te*getd(n/i)%mod);
        }
        return dd[n]=ans;
    }
    int main()
    {
        init();
        ll n;scanf("%lld",&n);
        ll ans=0;
        for(ll i=1,j;i<=n;i=j+1)
        {
            j=n/(n/i);
            ll te=(getmu(j)-getmu(i-1)+mod)%mod;
            add(ans,te*getd(n/i)%mod*getd(n/i)%mod);
        }
        printf("%lld
    ",ans);
        return 0;
    }
    /********************
    
    ********************/
    
    
  • 相关阅读:
    numpy金融函数
    Linux下shell编程
    numpy数组的排序,搜索,元素抽取
    cer格式证书转pem格式
    Facebook发行的新币Libra具体文档
    Golang包管理工具之govendor的使用
    nodejs安装依赖包使用阿里镜像
    ubuntu后台开启守护程序
    hyperledger cello部署
    fabric-smaple部署
  • 原文地址:https://www.cnblogs.com/acjiumeng/p/9744905.html
Copyright © 2020-2023  润新知