题意:题意省~
sol.考虑 你每一个排列的分数,是若干个循环长度的lcm
然后只要计数方案就好了
考虑 长度\(a_i\)的环有\(b_i\)个
那么这个环贡献的方案数就是
\[\frac{C^{a_i * b_i}_{rest}}{(b_i - 1)} * 分配的方案数 \]#include<bits/stdc++.h>
#define MAXN 55
typedef long long ll;
const ll mod = 998244353;
using namespace std;
int n,k;
ll C[MAXN][MAXN],ans = 1;
ll jc[MAXN],inv[MAXN];
ll mul(ll x , ll y){return x * y % mod;}
ll poww(ll x , int y){
ll zz = 1;
while(y){
if(y & 1)zz = zz * x % mod;
x = x * x % mod;
y = y >> 1;
}
return zz;
}
vector<int>q;
ll gcd(ll x , ll y){
if(!y)return x;
return gcd(y , x % y);
}
ll lcm(ll x , ll y){
ll zz = gcd(x , y);x /= zz;
return x * y;
}
map<int , int>mp;
void dfs(int now , int pre){
if(!now){
ll LCM = 1 , zz = 1;mp.clear();
for(int i = 0 ; i < q.size() ; i++)LCM = lcm(LCM , q[i]);
for(int i = 0 ; i < q.size() ; i++)mp[q[i]]++ , zz = zz * jc[q[i] - 1] % mod;
now = n;
for(auto it : mp){
zz = zz * C[now][(it.first) * (it.second)] % mod;
for(int i = 1 ; i <= it.second ; i++)zz = zz * C[i * it.first][it.first] % mod;
zz = zz * inv[it.second] % mod;
now -= it.first * it.second;
}
ans = (ans + zz * poww(LCM , zz) % mod) % mod;
return;
}
for(int i = pre ; i <= now ; i++){
q.push_back(i);
dfs(now - i , i);
q.pop_back();
}
}
int main(){
jc[0] = 1;for(int i = 1 ; i <= 50 ; i++)jc[i] = jc[i - 1] * i % mod;
for(int i = 0 ; i <= 50 ; i++)inv[i] = poww(jc[i] , mod - 2);
for(int i = 0 ; i <= 50 ; i++)
for(int i = 0 ; i <= 50 ; i++){
C[i][0] = 1;
for(int j = 1 ; j <= i ; j++)
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
}
scanf("%d%d" , &n , &k);
dfs(n , 1);
cout<<ans<<endl;
}