链接
题解
每个环的大小都是 K K K的约数即可
枚举编号最小的点所在的环的大小,用组合数学的方法计算
代码
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define iinf 0x3f3f3f3f
#define linf (1ll<<60)
#define eps 1e-8
#define maxn 55
#define cl(x) memset(x,0,sizeof(x))
#define rep(_,__) for(_=1;_<=(__);_++)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define de(x) cerr<<#x<<" = "<<x<<endl
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll read(ll x=0)
{
ll c, f(1);
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-f;
for(;isdigit(c);c=getchar())x=x*10+c-0x30;
return f*x;
}
#define mod 998244353ll
ll n, C[maxn][maxn], f[maxn], tot, K, d[maxn], fact[maxn];
int main()
{
ll i, j, k, T=read();
for(i=0;i<maxn;i++)C[i][0]=1;
rep(i,maxn-1)rep(j,i)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
fact[0]=1;
rep(i,maxn-1)fact[i]=fact[i-1]*i%mod;
while(T--)
{
n=read(), K=read();
cl(f);
f[0]=1;
rep(i,n)rep(j,i)
{
if(K%j==0)(f[i]+=f[i-j]*C[i-1][j-1]%mod*fact[j-1])%=mod;
}
printf("%lld\n",f[n]);
}
return 0;
}