• Luogu P5518 [MtOI2019]幽灵乐团


    Link

    [egin{aligned} ans&=prodlimits_{i=1}^aprodlimits_{j=1}^bprodlimits_{k=1}^c(frac{operatorname{lcm}(i,j)}{gcd(i,k)})^{f(i,j,k)}\ &=prodlimits_{i=1}^aprodlimits_{j=1}^bprodlimits_{k=1}^c(frac{ij}{gcd(i,j)gcd(i,k)})^{f(i,j,k)}\ end{aligned} ]

    ( ext{Let }P(a,b,c):=prodlimits_{i=1}^aprodlimits_{j=1}^bprodlimits_{k=1}^ci^{f(i,j,k)},Q(a,b,c):=prodlimits_{i=1}^aprodlimits_{j=1}^bprodlimits_{k=1}^c(gcd(i,j))^{f(i,j,k)}\ ext{Notice that }f(i,j,k) ext{ is rotating, so we have})

    [egin{aligned} ans&=prodlimits_{i=1}^aprodlimits_{j=1}^bprodlimits_{k=1}^c(frac{ij}{gcd(i,j)gcd(i,k)})^{f(i,j,k)}\ &=frac{P(a,b,c)P(b,a,c)}{Q(a,b,c)Q(a,c,b)} end{aligned} ]

    ( ext{Thus what we need to calculate is }P(a,b,c) ext{ and }Q(a,b,c).)

    ( ext{For convenience, let }(f imes g)(n) ext{ denote }prodlimits_{d|n}f(d)^{g(frac nd)},(fcdot g)(n) ext{ denote }f(n)^{g(n)} ext{ and }C(n) ext{ denote }frac{n(n+1)}2.)

    ( ext{Sub.1:}f(i,j,k)=1)

    [egin{aligned} P(a,b,c)&=prodlimits_{i=1}^aprodlimits_{j=1}^bprodlimits_{k=1}^ci\ &=(a!)^{bc}\ Q(a,b,c)&=prodlimits_{i=1}^aprodlimits_{j=1}^bprodlimits_{k=1}^cgcd(i,j)\ &=(prodlimits_{d=1}d^{sumlimits_{t=1}mu(t)lfloorfrac a{dt} floorlfloorfrac b{dt} floor})^c\ &=prodlimits_{d=1}(id imes mu)(d)^{clfloorfrac ad floorlfloorfrac bd floor} end{aligned} ]

    ( ext{Sub.2:}f(i,j,k)=ijk)

    [egin{aligned} P(a,b,c)&=prodlimits_{i=1}^aprodlimits_{j=1}^bprodlimits_{k=1}^ci^{ijk}\ &=(prodlimits_{i=1}^ai^i)^{C(b)C(c)}\ Q(a,b,c)&=prodlimits_{i=1}^aprodlimits_{j=1}^bprodlimits_{k=1}^cgcd(i,j)^{ijk}\ &=(prodlimits_{d=1}d^{d^2sumlimits_{t=1}mu(t)t^2C(lfloorfrac a{dt} floor)C(lfloorfrac b{dt} floor)})^{C(c)}\ &=prodlimits_{d=1}(id imesmucdot id_2)(d)^{C(c)C(lfloorfrac at floor)C(lfloorfrac bt floor)} end{aligned} ]

    ( ext{Sub.3:}f(i,j,k)=gcd(i,j,k))

    [egin{aligned} P(a,b,c)&=prodlimits_{i=1}^aprodlimits_{j=1}^bprodlimits_{k=1}^ci^{gcd(i,j,k)}\ &=prodlimits_{i=1}^ai^{sumlimits_{j=1}^bsumlimits_{k=1}^cgcd(i,j,k)}\ &=prodlimits_{i=1}^ai^{sumlimits_{d|i}varphi(d)lfloorfrac bd floorlfloorfrac cd floor}\ &=prodlimits_{d=1}^a((idcdotvarphi)(d)^{lfloorfrac ad floor}(lfloorfrac ad floor!)^{varphi(d)})^{lfloorfrac bd floorlfloorfrac cd floor}\ &=prodlimits_{d=1}^alfloorfrac ad floor!^{varphi(d)lfloorfrac bd floorlfloorfrac cd floor}prodlimits_{d=1}^a(idcdotvarphi)(d)^{lfloorfrac ad floorlfloorfrac bd floorlfloorfrac cd floor}\ Q(a,b,c)&=prodlimits_{i=1}^aprodlimits_{j=1}^bprodlimits_{k=1}^cgcd(i,j)^{gcd(i,j,k)}\ &=prodlimits_{d=1}^ad^{sumlimits_{t=1}mu(t)lfloorfrac a{dt} floorlfloorfrac b{dt} floorsumlimits_{k=1}^cgcd(d,k)}\ &=prodlimits_{d=1}^ad^{(sumlimits_{t=1}mu(t)lfloorfrac a{dt} floorlfloorfrac b{dt} floor)(sumlimits_{t|d}varphi(t)lfloorfrac ct floor)}\ &=prodlimits_{t=1}^aprodlimits_{d|t}prodlimits_{g|d}(frac dg)^{mu(frac td)varphi(g)lfloorfrac cg floorlfloorfrac at floorlfloorfrac bt floor}prodlimits_{t=1}^aprodlimits_{d|t}prodlimits_{g|d}g^{mu(frac td)varphi(g)lfloorfrac cg floorlfloorfrac at floorlfloorfrac bt floor}\ &=prodlimits_{g=1}^aprodlimits_{t=1}^{lfloorfrac ag floor}prodlimits_{d|t}d^{mu(frac td)varphi(g)lfloorfrac cg floorlfloorfrac a{tg} floorlfloorfrac b{tg} floor}prodlimits_{g=1}^a(idcdotvarphi)(g)^{sumlimits_{t=1}lfloorfrac cg floorlfloorfrac a{tg} floorlfloorfrac b{tg} floorsumlimits_{d|t}mu(frac td)}\ &=prodlimits_{g=1}^a(prodlimits_{t=1}^{lfloorfrac ag floor}(id imesmu)(t)^{lfloorfrac a{tg} floorlfloorfrac b{tg} floor})^{varphi(g)lfloorfrac cg floor}prodlimits_{g=1}^a(idcdotvarphi)(g)^{lfloorfrac ag floorlfloorfrac bg floorlfloorfrac cg floor} end{aligned} ]

    ( ext{Since }P(a,b,c) ext{ and }Q(a,b,c) ext{ have the same term }prodlimits_{g=1}^a(idcdotvarphi)(g)^{lfloorfrac ag floorlfloorfrac bg floorlfloorfrac cg floor} ext{, it can be eliminated from the answer!!1})

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using i64=long long;
    const int N=100007;
    int read(){int x;scanf("%d",&x);return x;}
    int P,mu[N],phi[N];i64 fac[N],f2[N],t1[N],t2[N],it1[N],it2[N],sum[N];
    i64 pow(i64 a,i64 b){i64 r=1;for(a%=P,b%=P-1,b+=b>>63&(P-1);b;b>>=1,a=a*a%P)if(b&1)r=r*a%P;return r;}
    i64 C(i64 x){return x*(x+1)/2%(P-1);}
    void Sieve(int n)
    {
        static int tot=0,pr[N],np[N];static i64 t[N];
        mu[1]=phi[1]=fac[0]=f2[0]=t1[0]=t2[0]=it1[0]=it2[0]=1;
        for(int i=2;i<=n;++i)
        {
    	if(!np[i]) pr[++tot]=i,mu[i]=-1,phi[i]=i-1;
    	for(int j=1;j<=tot&&i*pr[j]<=n;++j)
    	{
    	    if(np[i*pr[j]]=1,!(i%pr[j])) {phi[i*pr[j]]=phi[i]*pr[j];break;}
    	    mu[i*pr[j]]=-mu[i],phi[i*pr[j]]=phi[i]*(pr[j]-1);
    	}
        }
        for(int i=1;i<=n;++i) t[i]=1,fac[i]=i*fac[i-1]%P,f2[i]=f2[i-1]*pow(i,i)%P,t[i]=1,sum[i]=(sum[i-1]+phi[i])%(P-1);
        for(int i=1;i<=n;++i) for(int j=1;i*j<=n;++j) (t[i*j]*=pow(i,mu[j]))%=P;
        for(int i=1;i<=n;++i) it1[i]=pow(t1[i]=t1[i-1]*t[i]%P,P-2),it2[i]=pow(t2[i]=t2[i-1]*pow(t[i],1ll*i*i)%P,P-2);
    }
    i64 calc1(int a,int b)
    {
        i64 ans=1;
        for(int l=1,r;l<=a&&l<=b;l=r+1) r=std::min(a/(a/l),b/(b/l)),(ans*=pow(t1[r]*it1[l-1],1ll*(a/l)*(b/l)))%=P;
        return ans;
    }
    i64 calc2(int a,int b)
    {
        i64 ans=1;
        for(int l=1,r=0;l<=a&&l<=b;l=r+1) r=std::min(a/(a/l),b/(b/l)),(ans*=pow(t2[r]*it2[l-1],C(a/l)*C(b/l)))%=P;
        return  ans;
    }
    i64 calc3(int a,int b,int c)
    {
        i64 ans=1;
        for(int l=1,r;l<=a&&l<=b&&l<=c;l=r+1) r=std::min(std::min(a/(a/l),b/(b/l)),c/(c/l)),(ans*=pow(fac[a/l],(sum[r]-sum[l-1])*(b/l)%(P-1)*(c/l)))%=P;
        return ans;
    }
    i64 calc4(int a,int b,int c)
    {
        i64 ans=1;
        for(int l=1,r;l<=a&&l<=b&&l<=c;l=r+1) r=std::min(std::min(a/(a/l),b/(b/l)),c/(c/l)),(ans*=pow(calc1(a/l,b/l),(sum[r]-sum[l-1])*(c/l)))%=P;
        return ans;
    }
    i64 solve1(int a,int b,int c){return pow(fac[a],1ll*b*c)*pow(fac[b],1ll*a*c)%P*pow(calc1(a,b),c*(P-2ll))%P*pow(calc1(a,c),b*(P-2ll))%P;}
    i64 solve2(int a,int b,int c){return pow(f2[a],C(b)*C(c))*pow(f2[b],C(a)*C(c))%P*pow(calc2(a,b),C(c)*(P-2))%P*pow(calc2(a,c),C(b)*(P-2))%P;}
    i64 solve3(int a,int b,int c){return calc3(a,b,c)*calc3(b,a,c)%P*pow(calc4(a,b,c)*calc4(a,c,b),P-2)%P;}
    void solve()
    {
        int a=read(),b=read(),c=read();
        printf("%lld %lld %lld
    ",solve1(a,b,c),solve2(a,b,c),solve3(a,b,c));
    }
    int main()
    {
        int q=read();P=read(),Sieve(100000);
        while(q--) solve();
    }
    
  • 相关阅读:
    okHttp源码解析------待续
    AS: Unsupported method: AndroidProject.getPluginGeneration().
    vue项目根据不同环境调用不同请求地址
    文字跑马灯(无缝衔接) CSS+JS完美实现
    data 和 computed 的区别
    ES6解构赋值
    flex布局
    token验证
    vue组件传值
    vue钩子函数
  • 原文地址:https://www.cnblogs.com/cjoierShiina-Mashiro/p/12978691.html
Copyright © 2020-2023  润新知