P6788 「EZEC-3」四月樱花

P6788 「EZEC-3」四月樱花

链接

P6788 「EZEC-3」四月樱花

题解

难点只有一个:\(y^{d(y)}\) \(=\) \(\prod_{t|y} y\) \(=\) \(\prod_{t|y} t \cdot \frac{y}{t}\) \(=\) \(\prod_{t|y} t^{2}\)
然而这点我整场月赛都没想出来,技不如人甘拜下风。有了这个式子之后式子就随便推了。
出题人似乎稍微卡了一下\(O(n^{3/4})\) 的整除分块。。我卡了下常就过了。。

\(Code\)

#include <bits/stdc++.h>
#define LL long long
#define ull unsigned long long
using namespace std;
const int N=1e6+10;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(LL x){
    if(x>9) print(x/10);
    putchar(x%10+'0');
}

unsigned int n,P,pp;

LL sol(unsigned int x){
    LL re=0;
    unsigned int y,z=sqrt(x);
    for(unsigned int i=1;i<=z;++i){
        y=x/i;
        re+=y;
    }
    for(unsigned int i=z+1,j;i<=x;i=j){
        y=x/i;
        j=x/y+1;
        re+=(LL)y*(j-i);
    }
    return re%pp;
}
LL qpow(LL x,LL y){
    LL re=1;
    while(y){
        if(y&1) re=re*x%P;
        x=x*x%P;y>>=1;
    }
    return re;
}
int main(){
    cin>>n>>P;pp=P-1;
    unsigned int y,z;
    LL ans=1;
    for(unsigned int i=1,j;i<=n;i=j+1){
        z=n/i;
        j=n/z;
        y=sol(z);
        ans=ans*qpow((LL)i*qpow(j+1,P-2)%P,y)%P;
    }
    ans=ans*ans%P;
    cout<<ans<<endl;
    return 0;
}
posted @ 2020-09-03 17:14  Iscream-2001  阅读(165)  评论(0编辑  收藏  举报
/* */ /* */