Luogu P5518 [MtOI2019]幽灵乐团

Link

\[\begin{aligned} ans&=\prod\limits_{i=1}^a\prod\limits_{j=1}^b\prod\limits_{k=1}^c(\frac{\operatorname{lcm}(i,j)}{\gcd(i,k)})^{f(i,j,k)}\\ &=\prod\limits_{i=1}^a\prod\limits_{j=1}^b\prod\limits_{k=1}^c(\frac{ij}{\gcd(i,j)\gcd(i,k)})^{f(i,j,k)}\\ \end{aligned} \]

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

\[\begin{aligned} ans&=\prod\limits_{i=1}^a\prod\limits_{j=1}^b\prod\limits_{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} \]

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

\(\text{For convenience, let }(f\times g)(n)\text{ denote }\prod\limits_{d|n}f(d)^{g(\frac nd)},(f\cdot g)(n)\text{ denote }f(n)^{g(n)}\text{ and }C(n)\text{ denote }\frac{n(n+1)}2.\)

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

\[\begin{aligned} P(a,b,c)&=\prod\limits_{i=1}^a\prod\limits_{j=1}^b\prod\limits_{k=1}^ci\\ &=(a!)^{bc}\\ Q(a,b,c)&=\prod\limits_{i=1}^a\prod\limits_{j=1}^b\prod\limits_{k=1}^c\gcd(i,j)\\ &=(\prod\limits_{d=1}d^{\sum\limits_{t=1}\mu(t)\lfloor\frac a{dt}\rfloor\lfloor\frac b{dt}\rfloor})^c\\ &=\prod\limits_{d=1}(id\times \mu)(d)^{c\lfloor\frac ad\rfloor\lfloor\frac bd\rfloor} \end{aligned} \]

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

\[\begin{aligned} P(a,b,c)&=\prod\limits_{i=1}^a\prod\limits_{j=1}^b\prod\limits_{k=1}^ci^{ijk}\\ &=(\prod\limits_{i=1}^ai^i)^{C(b)C(c)}\\ Q(a,b,c)&=\prod\limits_{i=1}^a\prod\limits_{j=1}^b\prod\limits_{k=1}^c\gcd(i,j)^{ijk}\\ &=(\prod\limits_{d=1}d^{d^2\sum\limits_{t=1}\mu(t)t^2C(\lfloor\frac a{dt}\rfloor)C(\lfloor\frac b{dt}\rfloor)})^{C(c)}\\ &=\prod\limits_{d=1}(id\times\mu\cdot id_2)(d)^{C(c)C(\lfloor\frac at\rfloor)C(\lfloor\frac bt\rfloor)} \end{aligned} \]

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

\[\begin{aligned} P(a,b,c)&=\prod\limits_{i=1}^a\prod\limits_{j=1}^b\prod\limits_{k=1}^ci^{\gcd(i,j,k)}\\ &=\prod\limits_{i=1}^ai^{\sum\limits_{j=1}^b\sum\limits_{k=1}^c\gcd(i,j,k)}\\ &=\prod\limits_{i=1}^ai^{\sum\limits_{d|i}\varphi(d)\lfloor\frac bd\rfloor\lfloor\frac cd\rfloor}\\ &=\prod\limits_{d=1}^a((id\cdot\varphi)(d)^{\lfloor\frac ad\rfloor}(\lfloor\frac ad\rfloor!)^{\varphi(d)})^{\lfloor\frac bd\rfloor\lfloor\frac cd\rfloor}\\ &=\prod\limits_{d=1}^a\lfloor\frac ad\rfloor!^{\varphi(d)\lfloor\frac bd\rfloor\lfloor\frac cd\rfloor}\prod\limits_{d=1}^a(id\cdot\varphi)(d)^{\lfloor\frac ad\rfloor\lfloor\frac bd\rfloor\lfloor\frac cd\rfloor}\\ Q(a,b,c)&=\prod\limits_{i=1}^a\prod\limits_{j=1}^b\prod\limits_{k=1}^c\gcd(i,j)^{\gcd(i,j,k)}\\ &=\prod\limits_{d=1}^ad^{\sum\limits_{t=1}\mu(t)\lfloor\frac a{dt}\rfloor\lfloor\frac b{dt}\rfloor\sum\limits_{k=1}^c\gcd(d,k)}\\ &=\prod\limits_{d=1}^ad^{(\sum\limits_{t=1}\mu(t)\lfloor\frac a{dt}\rfloor\lfloor\frac b{dt}\rfloor)(\sum\limits_{t|d}\varphi(t)\lfloor\frac ct\rfloor)}\\ &=\prod\limits_{t=1}^a\prod\limits_{d|t}\prod\limits_{g|d}(\frac dg)^{\mu(\frac td)\varphi(g)\lfloor\frac cg\rfloor\lfloor\frac at\rfloor\lfloor\frac bt\rfloor}\prod\limits_{t=1}^a\prod\limits_{d|t}\prod\limits_{g|d}g^{\mu(\frac td)\varphi(g)\lfloor\frac cg\rfloor\lfloor\frac at\rfloor\lfloor\frac bt\rfloor}\\ &=\prod\limits_{g=1}^a\prod\limits_{t=1}^{\lfloor\frac ag\rfloor}\prod\limits_{d|t}d^{\mu(\frac td)\varphi(g)\lfloor\frac cg\rfloor\lfloor\frac a{tg}\rfloor\lfloor\frac b{tg}\rfloor}\prod\limits_{g=1}^a(id\cdot\varphi)(g)^{\sum\limits_{t=1}\lfloor\frac cg\rfloor\lfloor\frac a{tg}\rfloor\lfloor\frac b{tg}\rfloor\sum\limits_{d|t}\mu(\frac td)}\\ &=\prod\limits_{g=1}^a(\prod\limits_{t=1}^{\lfloor\frac ag\rfloor}(id\times\mu)(t)^{\lfloor\frac a{tg}\rfloor\lfloor\frac b{tg}\rfloor})^{\varphi(g)\lfloor\frac cg\rfloor}\prod\limits_{g=1}^a(id\cdot\varphi)(g)^{\lfloor\frac ag\rfloor\lfloor\frac bg\rfloor\lfloor\frac cg\rfloor} \end{aligned} \]

\(\text{Since }P(a,b,c)\text{ and }Q(a,b,c)\text{ have the same term }\prod\limits_{g=1}^a(id\cdot\varphi)(g)^{\lfloor\frac ag\rfloor\lfloor\frac bg\rfloor\lfloor\frac cg\rfloor}\text{, 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\n",solve1(a,b,c),solve2(a,b,c),solve3(a,b,c));
}
int main()
{
    int q=read();P=read(),Sieve(100000);
    while(q--) solve();
}
posted @ 2020-05-28 10:10  Shiina_Mashiro  阅读(211)  评论(0编辑  收藏  举报