Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Code : Count Arrays with Fixed Product

#include <atcoder/modint>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;
using mint = modint998244353;

int maxn = (int)1e6 + 1;
vector<mint> fac;

void precompute_factorial() {
    fac.resize(maxn + 1);

    fac[0] = 1;
    for (int i = 1; i < maxn; i++) {
        fac[i] = i * fac[i - 1];
    }
}

mint comb(int n, int r) {
    if (r < 0 || r > n) {
        return 0;
    }
    return fac[n] / (fac[n - r] * fac[r]);
}

void solve(long long P, int L) {
    vector<int> exp;
    long long up = P;
    for (long long now = 2; now * now <= up; now++) {
        int cnt = 0;
        while (P % now == 0) {
            P /= now;
            cnt++;
        }
        if (cnt) {
            exp.push_back(cnt);
        }
    }
    if (P > 1) {
        exp.push_back(1);
    }

    mint res = 1;
    for (int alpha : exp) {
        res *= comb(L + alpha - 1, alpha);
    }
    cout << res.val() << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    precompute_factorial();
    long long P;
    int L;
    cin >> P >> L;
    solve(P, L);
    return 0;
}