JZOJ5813Count-質因數分解+dp

#include <cstdio>
#include <algorithm>
#include <cstring>
#define MOD 998244353
 
using namespace std;
typedef long long LL;
LL dp[10000][220], all;
int cc[110];
 
inline LL qui_pow(LL x, register int y) {
    if (y == 1) return x;
    LL t = qui_pow(x, y / 2);
    if (y & 1) return t * t % MOD * x % MOD;
    else return t * t % MOD;
}
 
int main() {
    register int n, m, tot = 1;
    scanf("%d%d", &n, &m);
    register int nn = n;
    for (register int i = 2; i * i <= n; ++i) {
        if (!(nn % i)) {
            register int cnt = 1;
            while (!(nn % i)) {
                nn /= i;
                cnt++;
            }
            cc[++cc[0]] = cnt - 1;
            tot *= cnt;
        }
    }
    if (nn > 1) tot <<= 1, cc[++cc[0]] = 1;
    LL all = 1;
    for (register int l = 1; l <= cc[0]; ++l) {
        memset(dp, 0, sizeof dp);
    register int lim = cc[l] * m;
    dp[0][0] = 1;
    for (register int i = 0; i <= lim; ++i) {
        for (register int j = 1; j <= m * 2; ++j) {
            for (register int k = 0; k <= min(i, cc[l]); ++k) {
                dp[i][j] += dp[i - k][j - 1];
            }
            dp[i][j] %= MOD;
        }
    }
        all = all * dp[lim][m << 1] % MOD;
        if (all >= MOD) all -= MOD;
    }
    LL ans = (qui_pow(tot, m << 1) + all) * qui_pow(2, MOD - 2) % MOD;
    printf("%lld\n", ans);
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章