以下是用Python实现的代码:

Mod = 998244353 fac = [0] * 55 ifac = [0] * 55 pow = [0] * 55 ans = 0

def Inv(x): return x if x == 1 else (Mod - Mod // x) * Inv(Mod % x) % Mod

def Gcd(a, b): return Gcd(b, a % b) if b else a

def DFS(d, c, l): global ans if c == 0: tot = 1 t = 0 for i in range(1, d+1): tot = tot * Inv(st[i]) % Mod for i in range(1, d+1): if st[i] != st[i-1]: tot = tot * ifac[t] % Mod t = 1 else: t += 1 tot = tot * ifac[t] % Mod for i in range(1, d+1): tot = tot * pow[st[i]//2] % Mod for i in range(1, d+1): for j in range(i+1, d+1): tot = tot * pow[Gcd(st[i], st[j])] % Mod ans = (ans + tot) % Mod for i in range(l, c+1): st[d+1] = i DFS(d+1, c-i, i)

n, m = map(int, input().split()) pow[0] = fac[0] = ifac[0] = 1 for i in range(1, n+1): fac[i] = fac[i-1] * i % Mod pow[i] = pow[i-1] * m % Mod ifac[i] = Inv(fac[i]) DFS(0, n, 1) print(ans

请你用python语言实现这段代码:#include iostream#include cstring#include cstdiousing namespace std;typedef long long LL;const int N=55;int stN;LL nmMod=998244353facNifacNpowNans;LL InvLL xreturn x==1xMod-ModxInvMo

原文地址: http://www.cveoy.top/t/topic/iJqG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录