結果

問題 No.2902 ZERO!!
ユーザー Today03Today03
提出日時 2024-09-27 21:57:17
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 341 ms / 2,000 ms
コード長 5,094 bytes
コンパイル時間 3,812 ms
コンパイル使用メモリ 265,864 KB
実行使用メモリ 128,948 KB
最終ジャッジ日時 2024-09-27 21:57:32
合計ジャッジ時間 9,229 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 10;
const ll INFL = 4e18;

/*
    考察
    b=N!のとき、e_b=1
    b=(N!-1)のとき、e_b=0かな?

    N!の素因数分解ができるのか
    だから、e_bが1になるのはいくつ、e_bが2になるのはいくつ。。。みたいにやることを考える。

    e_b=1以上となるのは、全ての素因数について指数/1以下
    e_b=2以上となるのは、全ての素因数について指数/2以下
    e_b=i以上となるのは、全ての素因数について指数/i以下
*/

template <ll MOD>
struct ModInt {
    ll value;
    ModInt(ll x = 0) {
        if (x >= 0) {
            value = x % MOD;
        } else {
            value = MOD - (-x) % MOD;
        }
    }
    ModInt operator-() const { return ModInt(-value); }
    ModInt operator+() const { return ModInt(*this); }
    ModInt &operator+=(const ModInt &other) {
        value += other.value;
        if (value >= MOD) value -= MOD;
        return *this;
    }
    ModInt &operator-=(const ModInt &other) {
        value += MOD - other.value;
        if (value >= MOD) value -= MOD;
        return *this;
    }
    ModInt &operator*=(const ModInt other) {
        value = value * other.value % MOD;
        return *this;
    }
    ModInt &operator/=(ModInt other) {
        (*this) *= other.inv();
        return *this;
    }
    ModInt operator+(const ModInt &other) const { return ModInt(*this) += other; }
    ModInt operator-(const ModInt &other) const { return ModInt(*this) -= other; }
    ModInt operator*(const ModInt &other) const { return ModInt(*this) *= other; }
    ModInt operator/(const ModInt &other) const { return ModInt(*this) /= other; }
    ModInt pow(ll x) const {
        ModInt ret(1), mul(value);
        while (x) {
            if (x & 1) ret *= mul;
            mul *= mul;
            x >>= 1;
        }
        return ret;
    }
    ModInt inv() const { return pow(MOD - 2); }
    bool operator==(const ModInt &other) const { return value == other.value; }
    bool operator!=(const ModInt &other) const { return value != other.value; }
    friend ostream &operator<<(ostream &os, const ModInt &x) { return os << x.value; }
    friend istream &operator>>(istream &is, ModInt &x) {
        ll v;
        is >> v;
        x = ModInt<MOD>(v);
        return is;
    }
    static constexpr ll get_mod() { return MOD; }
};
using Mod998 = ModInt<998244353>;
using Mod107 = ModInt<1000000007>;

using mint = Mod998;

struct Factors {
    Factors(int n) {
        mx = n;
        min_factor = vector<int>(mx + 1);
        is_prime = vector<bool>(mx + 1, true);
        is_prime[0] = is_prime[1] = false;
        divisors = vector<vector<int>>(mx + 1);
        prime_factors = vector<vector<pair<int, int>>>(mx + 1);
        for (int i = 2; i <= mx; i++) {
            if (is_prime[i]) {
                min_factor[i] = i;
                for (int j = 2 * i; j <= mx; j += i) {
                    is_prime[j] = false;
                    if (min_factor[j] == 0) {
                        min_factor[j] = i;
                    }
                }
            }
        }
    }
    vector<pair<int, int>> get_prime_factors(int n) {
        if (prime_factors[n].size() == 0) {
            int x = n;
            while (x > 1) {
                int p = min_factor[x];
                int cnt = 0;
                while (x % p == 0) {
                    x /= p;
                    cnt++;
                }
                prime_factors[n].push_back({p, cnt});
            }
        }
        return prime_factors[n];
    }
    vector<int> get_divisors(int n) {
        if (divisors[n].size() == 0) {
            vector<pair<int, int>> pf = get_prime_factors(n);
            int sz = pf.size();
            auto dfs = [&](auto &&dfs, int i, int x) -> void {
                if (i == sz) {
                    divisors[n].push_back(x);
                    return;
                }
                auto [p, cnt] = pf[i];
                for (int j = 0; j <= cnt; j++) {
                    dfs(dfs, i + 1, x);
                    x *= p;
                }
            };
            dfs(dfs, 0, 1);
            sort(divisors[n].begin(), divisors[n].end());
        }
        return divisors[n];
    }

private:
    int mx;
    vector<int> min_factor;
    vector<bool> is_prime;
    vector<vector<int>> divisors;
    vector<vector<pair<int, int>>> prime_factors;
};

int main() {
    int N;
    cin >> N;

    Factors fac(N);
    vector<int> cnt(N + 1);
    int all = 0;
    for (int i = 2; i <= N; i++) {
        auto pf = fac.get_prime_factors(i);
        for (auto [p, e] : pf) {
            cnt[p] += e;
            all += e;
        }
    }
    int mx = ranges::max(cnt);

    vector<mint> prod(all + 1, 1);
    for (int i = 2; i <= N; i++) {
        if (cnt[i] == 0) continue;
        for (int j = 1; j <= cnt[i]; j++) {
            prod[j] *= (cnt[i] / j + 1);
        }
    }

    mint ans = 0;
    for (int i = 1; i <= mx; i++) ans += prod[i] - 1;

    cout << ans << endl;
}
0