P3768 simple math problems

The meaning of problems

A first inversion波莫比乌斯available (too lazy to write a latex):
set \ (SUM (X) = \ SUM \ limits_. 1} = {I ^ XI \)
\ (ANS = \ SUM \ T = {limits_ 1} ^ {n} sum (
\ frac {n} {T}) ^ 2T ^ 2 \ sum \ limits_ {d | n} d \ mu (\ frac {T} {d}) \) have \ (id * \ mu = \ varphi \)
proof:
a \ (id = \ varphi * 1,1 * \ mu = \ epsilon \) can be obtained:
\ (ID * \ MU = \ varphi. 1 * * \ mu-> ID * \ mu = \ varphi \)
know after:
\ (\ SUM \ limits_ {T =. 1} ^ {n-} SUM (\ FRAC {n-} {T}) ^ 2T ^ 2 \ varphi (T) \)
clearly be preceded by block division, consider how to find \ (T ^ 2 \ varphi ( T) \)

Set \ (F (I) = I ^ 2 * \ varphi (I) \) , found that this is a multiplicative function, consider Du teach sieve:
set \ (S (n) = \ sum \ limits_ {i = 1} ^ {n} f (i) \
) to teach DU sieve routine formula:
\ (G (. 1) * S (n-) = \ SUM \ limits_. 1} ^ {n-I = (F * G) (I) - \ sum \ limits_ {i = 2
} ^ ng (i) * f (\ frac {n} {i}) \) consider finding a suitable \ (G \) : \ ((F
* G) (n-) = \ SUM \ limits_ {D | n-} G (D) * F (\ FRAC {n-} {D}) \)
\ (= \ SUM \ limits_ {D | N} G (D) * \ FRAC {n-^ 2} {d ^ 2} \ varphi (
\ frac {n} {d}) \) Since \ (\ SUM \ limits_ {D | n-} \ varphi (D) = n-\) , so order \ (g (x) = X ^ 2 \)
\ (= \ SUM \ limits_ {D | n-} D ^ 2 * \ FRAC {n-^ 2} {D ^ 2} \ varphi (\ FRAC {n-} {D}) \)
\ (= \ SUM \ limits_ {D | n-} n-^ 2 \ varphi (\ FRAC {n-} {D}) \)
\ (= n-^ 2 \ SUM \ limits_ {D | n-} \ varphi (\ FRAC {n-} { } D) \)
\ (n-^ =. 3 \)
Therefore, when \ (g (x) = x ^ 2 \) when, \ ((F * G) (X) = X ^. 3 \)

Thus the first screen and then dividing Du taught to block.

code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=8*1e6+10;
ll n,mod,inv2,inv6,ans;
ll phi[maxn],sum[maxn];
bool vis[maxn];
vector<int>prime;
unordered_map<ll,ll>mp;
inline ll sqr(ll x){return x*x%mod;}
inline ll calc1(ll x){x%=mod;return x*(x+1)%mod*(2*x+1)%mod*inv6%mod;}
inline ll calc2(ll x){x%=mod;return x*(x+1)%mod*inv2%mod;}
inline ll power(ll x,ll k,ll mod)
{
    ll res=1;
    while(k)
    {
        if(k&1)res=res*x%mod;
        x=x*x%mod;k>>=1;
    }
    return res;
}
inline void pre_work(int n)
{
    vis[1]=1;phi[1]=1;
    for(int i=2;i<=n;i++)
    {
        if(!vis[i])prime.push_back(i),phi[i]=(i-1)%mod;
        for(unsigned int j=0;j<prime.size()&&i*prime[j]<=n;j++)
        {
            vis[i*prime[j]]=1;
            if(i%prime[j]==0)
            {
                phi[i*prime[j]]=1ll*phi[i]*prime[j]%mod;
                break;
            }
            phi[i*prime[j]]=1ll*phi[i]*phi[prime[j]]%mod;           
        }
    }
    for(int i=1;i<=n;i++)sum[i]=(sum[i-1]+1ll*phi[i]*i%mod*i%mod)%mod;
}
inline ll getsum(ll x)
{
    if(x<=8000000)return sum[x];
    if(mp.count(x))return mp[x];
    ll res=sqr(calc2(x));
    for(ll l=2,r;l<=x;l=r+1)
    {
        r=x/(x/l);
        res-=(calc1(r)-calc1(l-1))%mod*getsum(x/l)%mod;
        res%=mod;
    }
    return mp[x]=(res+mod)%mod;
}
int main()
{
    scanf("%lld%lld",&mod,&n);
    inv2=power(2,mod-2,mod),inv6=power(6,mod-2,mod);
    pre_work(8000000);
    for(ll l=1,r;l<=n;l=r+1)
    {
        r=n/(n/l);
        ans=(ans+sqr(calc2(n/l))*(getsum(r)-getsum(l-1))%mod+mod)%mod;
    }
    printf("%lld",(ans+mod)%mod);
    return 0;
}

Guess you like

Origin www.cnblogs.com/nofind/p/11953816.html