2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 huntian oy

 

http://acm.hdu.edu.cn/showproblem.php?pid=6706

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#include
using namespace std;

#define sfi(i) scanf("%d",&i)
#define sfl(i) scanf("%I64d",&i)
#define sfs(i) scanf("%s",(i))
#define pri(i) printf("%d\n",i)
#define prl(i) printf("%I64d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-10
#define PI acos(-1.0)
#define lowbit(x) ((x)&(-x))
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define endl '\n'
#define pb push_back
#define lson (rt<<1)
#define rson (rt<<1|1)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

templateinline void read(T &x)
{
    x=0;
    static int p;p=1;
    static char c;c=getchar();
    while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
    while(isdigit(c)) {x=(x<<1)+(x<<3)+(c-48);c=getchar();}
    x*=p;
}

const int maxn=1e6+9;
const int mod=1e9+7;

//tr1::unordered_mapw1;
tr1::unordered_mapw2;
bool check[maxn+10];
int prime[maxn+10];
//int mu[maxn+10];
int phi[maxn+10];

//int sum1[maxn+10];
ll sum2[maxn+10];


ll power(ll x,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return ans;
}

ll inv2=power(2LL,mod-2);
ll inv6=power(6LL,mod-2);

void Mobius_phi(int N)
{
    mem(check,0);
    //mu[1]=1;
    phi[1]=1;
    int tot=0;
    for(int i=2;i<=N;i++)
    {
        if(!check[i])
        {
            prime[tot++]=i;
            //mu[i]=-1;
            phi[i]=i-1;
        }
        for(int j=0;jN) break;
            check[i*prime[j]]=true;
            if(i%prime[j]==0)
            {
                //mu[i*prime[j]]=0;
                phi[i*prime[j]]=(ll)phi[i]*prime[j]%mod;
                break;
            }
            else
            {
                //mu[i*prime[j]]=-mu[i];
                phi[i*prime[j]]=(ll)phi[i]*(prime[j]-1)%mod;
            }
        }
    }

    for(int i=1;i<=N;i++)
    {
        //sum1[i]=sum1[i-1]+mu[i];
        sum2[i]=(sum2[i-1]+(ll)phi[i]*i%mod)%mod;
    }

}

//int djsmu(int x)
//{
//    if(x<=5000000) return sum1[x];
//    if(w1[x]) return w1[x];
//    int ans=1;//h(x)前n项和
//    for(int l=2,r;l<=x;l=r+1)
//    {
//        r=x/(x/l);
//        ans-=(r-l+1)*djsmu(x/l);
//    }
//    w1[x]=ans;
//    return ans;
//}

ll djsphi(int x)
{
    if(x<=1000000) return sum2[x]%mod;
    if(w2[x]!=0) return w2[x];
    ll ans=(ll)(x)*(x+1LL)%mod*(x*2+1LL)%mod*inv6%mod;
    for(ll l=2,r;l<=x;l=r+1)
    {
        r=x/(x/l);
        ll sumd=((r*(r+1)/2)%mod-(l*(l-1)/2)%mod+mod)%mod;
        ans=(ans-(sumd*djsphi(x/l)%mod)+mod)%mod;
    }
    return w2[x]=ans;
}

int main()
{
    //FAST_IO;
    //freopen("input.txt","r",stdin);

    //cout<>T;
    //read(T);
    sfi(T);

    while(T--)
    {
        int n;
        //cin>>n;
        //read(n);
        int a,b;
        scanf("%d%d%d",&n,&a,&b);
        //read(a);
        //read(b);
        //cout<>n>>a>>b)
//    {
//        ll sum=0;
//        for(ll i=1;i<=n;i++)
//        {
//            for(ll j=1;j<=i;j++)
//            {
//                ll ia=power(i,a);
//                ll ja=power(j,a);
//                ll ib=power(i,b);
//                ll jb=power(j,b);
//
//                ll g=__gcd(i,j);
//                if(g==1)
//                {
//                    ll gg=__gcd(ia-ja,ib-jb);
//                    sum+=gg;
//                    cout<<"i:"<

 

你可能感兴趣的:(杜教筛)