题目
思路
使用polya引理。
1
∣
G
∣
=
1
n
!
{1 \over |G|}={1\over n!}
∣G∣1=n!1
而轮换总方案数为
n
!
∏
b
i
∏
c
!
n!\over \prod b_i \prod c!
∏bi∏c!n!
所以最后的式子是
∑
b
1
∏
b
i
∏
c
!
m
∑
i
<
j
g
c
d
(
i
,
j
)
\sum_b{1\over \prod b_i \prod c!}m^{\sum_{i<j}gcd(i,j)}
∑b∏bi∏c!1m∑i<jgcd(i,j)
dfs解决
code:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
long long a[80],ans,n,b[80],myd;
long long m;
long long ksm(long long x,long long y)
{
long long s=1;
while (y)
{
if (y&1) s=s*x%myd;
x=x*x%myd;
y>>=1;
}
return s;
}
long long gcd(long long x,long long y)
{
long long r=x%y;
while (r!=0)
{
x=y,y=r,r=x%y;
}
return y;
}
void dfs(long long tot,long long syg,long long s)
{
if (s==0)
{
long long x=0,y=1;
for (int i=1,j=1;i<tot;i++)
{
j=1;
x+=b[i]>>1;
while (j<i)
{
x+=gcd(b[i],b[j]);
j++;
}
y=y*b[i]%myd;
}
for (int i=1,j=1;i<tot;i=j)
{
while (b[i]==b[j]&&j<tot) j++;
y=y*a[j-i]%myd;
}
ans=(ans+ksm(m,x)*ksm(y,myd-2)%myd)%myd;
return;
}
for (int i=syg;i<=s;i++)
{
b[tot]=i;
dfs(tot+1,i,s-i);
}
return;
}
int main()
{
cin>>n>>m>>myd;
a[0]=1;
for (int i=1;i<=80;i++) a[i]=a[i-1]*i%myd;
ans=0;
dfs(1,1,n);
cout<<ans;
return 0;
}
机房某daolao:据说有色图??