[关闭]
@xiaoziyao 2020-04-09T21:19:18.000000Z 字数 16633 阅读 1264

[MtOI2019]幽灵乐团解题报告

解题报告


[MtOI2019]幽灵乐团解题报告:

题意:共组数据,给定求对于每个,其中:
数据范围:
这道题的公式真的是精神污染。。。
首先我们可以将原式化为,因此我们可以分为两部分来做这道题,即求

  1. #include<stdio.h>
  2. const int maxn=100005;
  3. long long i,j,k,m,n,T,p,A,B,C,l,r,cnt;
  4. long long a[maxn],c[maxn],mu[maxn],varphi[maxn],fac1[maxn],fac2[maxn],w1[maxn],f1[maxn],g1[maxn],w2[maxn],f2[maxn],g2[maxn],w3[maxn],f3[maxn],g3[maxn],sum[maxn];
  5. //a[i]={Prime},c[i]=[i\in{Prime}?]
  6. //mu[i]=(i==1?)1:((i=\prod_{j=1}^s p_i,(p_x!=p_y(x!=y)))? 0:(-1)^s)
  7. //fac1[i]=i!,fac2[i]=\prod_{j=1}^i i^i
  8. //w1[i]=\prod_{d|i}i^{\mu(d/i)},f1[i]=\prod_{j=1}^i w1[i],g1[i]=f1[i]^{-1}
  9. //w2[i]=w1[i]*(i^2),f2[i]=\prod_{j=1}^i w2[i],g2[i]=f2[i]^{-1}
  10. //w3[i]=i^{\varphi(i)},f3[i]=\prod_{j=1]^i w3[i],g3[i]=f3[i]^{-1}
  11. //sum[i]=\sum_{j=1}^i varphi[i]
  12. inline long long min(long long a,long long b){
  13. return a<b? a:b;
  14. }
  15. long long ksm(long long a,long long b,long long p){
  16. long long res=1;
  17. while(b>0){
  18. if(b&1)
  19. res=(res*a)%p;
  20. a=(a*a)%p,b>>=1;
  21. }
  22. return res;
  23. }
  24. long long inv(long long a,long long b){
  25. return ksm(a,b-2,b);
  26. }
  27. void init(){
  28. c[1]=mu[1]=varphi[1]=1;
  29. for(long long i=2;i<maxn;i++){
  30. if(c[i]==0)
  31. a[++cnt]=i,mu[i]=-1,varphi[i]=i-1;
  32. for(long long j=1;j<=cnt;j++){
  33. if(i*a[j]>=maxn)
  34. break;
  35. c[i*a[j]]=1;
  36. if(i%a[j]==0){
  37. mu[i*a[j]]=0;
  38. varphi[i*a[j]]=varphi[i]*a[j];
  39. break;
  40. }
  41. mu[i*a[j]]=-mu[i];
  42. varphi[i*a[j]]=varphi[i]*(a[j]-1);
  43. }
  44. }
  45. fac1[0]=1;
  46. for(long long i=1;i<maxn;i++)
  47. fac1[i]=fac1[i-1]*i%p;
  48. fac2[0]=1;
  49. for(long long i=1;i<maxn;i++)
  50. fac2[i]=fac2[i-1]*ksm(i,i%(p-1),p)%p;
  51. for(long long i=0;i<maxn;i++)
  52. w1[i]=w2[i]=1;
  53. for(long long i=1;i<maxn;i++){
  54. if(mu[i]==0)
  55. continue;
  56. for(long long j=i;j<maxn;j+=i){
  57. if(mu[i]==1)
  58. w1[j]=(w1[j]*(j/i))%p;
  59. if(mu[i]==-1)
  60. w1[j]=(w1[j]*inv(j/i,p))%p;
  61. }
  62. }
  63. f1[0]=g1[0]=1;
  64. for(long long i=1;i<maxn;i++)
  65. f1[i]=f1[i-1]*w1[i]%p,g1[i]=inv(f1[i],p);
  66. for(long long i=1;i<maxn;i++)
  67. w2[i]=ksm(w1[i],i*i%(p-1),p);
  68. f2[0]=g2[0]=1;
  69. for(long long i=1;i<maxn;i++)
  70. f2[i]=f2[i-1]*w2[i]%p,g2[i]=inv(f2[i],p);
  71. for(long long i=1;i<maxn;i++)
  72. w3[i]=ksm(i,varphi[i],p);
  73. f3[0]=g3[0]=1;
  74. for(long long i=1;i<maxn;i++)
  75. f3[i]=f3[i-1]*w3[i]%p,g3[i]=inv(f3[i],p);
  76. for(long long i=1;i<maxn;i++)
  77. sum[i]=sum[i-1]+varphi[i];
  78. }
  79. inline long long getsum(long long x,long long p){
  80. return x*(x+1)/2%p;
  81. }
  82. long long getnmt(long long A,long long B,long long C,long long t){
  83. if(t==0){
  84. long long res=ksm(fac1[A],B*C%(p-1),p);
  85. return res;
  86. }
  87. if(t==1){
  88. long long res=ksm(fac2[A],getsum(B,p-1)*getsum(C,p-1)%(p-1),p);
  89. return res;
  90. }
  91. if(t==2){
  92. long long l=1,r,res=1;
  93. while(l<=min(min(A,B),C)){
  94. r=min(min(A/(A/l),B/(B/l)),C/(C/l));
  95. res=res*ksm(f3[r]*g3[l-1]%p,(A/l)*(B/l)%(p-1)*(C/l)%(p-1),p)%p*ksm(fac1[A/l],(sum[r]-sum[l-1]+(p-1))%(p-1)*(B/l)%(p-1)*(C/l)%(p-1),p)%p;
  96. l=r+1;
  97. }
  98. return res;
  99. }
  100. }
  101. long long getres(long long A,long long B){
  102. long long l=1,r,res=1;
  103. while(l<=min(A,B)){
  104. r=min(A/(A/l),B/(B/l));
  105. res=res*ksm(f1[r]*g1[l-1]%p,(A/l)*(B/l)%(p-1),p)%p;
  106. l=r+1;
  107. }
  108. return res;
  109. }
  110. long long getdmt(long long A,long long B,long long C,long long t){
  111. if(t==0){
  112. long long l=1,r,res=1;
  113. while(l<=min(A,B)){
  114. r=min(A/(A/l),B/(B/l));
  115. res=(res*ksm(f1[r]*g1[l-1]%p,(A/l)*(B/l)%(p-1),p))%p;
  116. l=r+1;
  117. }
  118. return ksm(res,C,p);
  119. }
  120. if(t==1){
  121. long long l=1,r,res=1;
  122. while(l<=min(A,B)){
  123. r=min(A/(A/l),B/(B/l));
  124. res=(res*ksm(f2[r]*g2[l-1]%p,getsum(A/l,p-1)*getsum(B/l,p-1)%(p-1),p))%p;
  125. l=r+1;
  126. }
  127. return ksm(res,getsum(C,p-1),p);
  128. }
  129. if(t==2){
  130. long long l=1,r,res=1;
  131. while(l<=min(min(A,B),C)){
  132. r=min(min(A/(A/l),B/(B/l)),C/(C/l));
  133. res=res*ksm(getres(A/l,B/l),(sum[r]-sum[l-1]+(p-1))%(p-1)*(C/l)%(p-1),p)%p*ksm(f3[r]*g3[l-1]%p,(A/l)*(B/l)%(p-1)*(C/l)%(p-1),p)%p;
  134. l=r+1;
  135. }
  136. return res;
  137. }
  138. }
  139. long long getans(long long A,long long B,long long C,long long t){
  140. long long nmt=getnmt(A,B,C,t)*getnmt(B,A,C,t)%p,dmt=getdmt(A,B,C,t)*getdmt(A,C,B,t)%p;
  141. return nmt*inv(dmt,p)%p;
  142. }
  143. int main(){
  144. scanf("%lld%lld",&T,&p);
  145. init();
  146. while(T--){
  147. scanf("%lld%lld%lld",&A,&B,&C);
  148. printf("%lld %lld %lld\n",getans(A,B,C,0),getans(A,B,C,1),getans(A,B,C,2));
  149. }
  150. return 0;
  151. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注