QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#770866#9553. The HermitvwxyzCompile Error//Python31.7kb2024-11-22 00:59:202024-11-22 00:59:20

Judging History

你现在查看的是最新测评结果

  • [2024-11-22 00:59:20]
  • 评测
  • [2024-11-22 00:59:20]
  • 提交

answer

#include <iostream>
#include <vector>
using namespace std;

const int mod = 998244353;
vector<long long> fact, fact_inve;

// モジュロの逆元を計算する関数
long long mod_pow(long long x, long long y, long long m) {
    long long res = 1;
    while (y > 0) {
        if (y % 2 == 1) res = res * x % m;
        x = x * x % m;
        y /= 2;
    }
    return res;
}

// 組み合わせ計算用関数
long long Comb(int n, int m) {
    if (n < m || n < 0) return 0;
    return fact[n] * fact_inve[n - m] % mod * fact_inve[m] % mod;
}

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

    // 階乗と階乗の逆元の計算
    fact.push_back(1);
    for (int i = 1; i <= N + M; i++) {
        fact.push_back(fact.back() * i % mod);
    }

    fact_inve.resize(N + M + 1);
    for (int i = 0; i <= N + M; i++) {
        fact_inve[i] = mod_pow(fact[i], mod - 2, mod);
    }

    int NN = min(N, 20);
    vector<vector<int>> D(M + 1);
    for (int d = 1; d <= M; d++) {
        for (int m = 2 * d; m <= M; m += d) {
            D[m].push_back(d);
        }
    }

    vector<vector<long long>> dp(NN, vector<long long>(M + 1, 0));
    long long ans = Comb(M, N) * N % mod;

    for (int n = 0; n < NN; n++) {
        for (int m = 1; m <= M; m++) {
            if (n == 0) {
                dp[0][m] = 1;
            } else {
                for (int d : D[m]) {
                    dp[n][m] += dp[n - 1][d];
                    dp[n][m] %= mod;
                }
            }
            ans -= dp[n][m] * Comb(M / m - 1, N - 1 - n) % mod;
            ans = (ans + mod) % mod;
        }
    }

    cout << ans << endl;
    return 0;
}

詳細信息

  File "answer.code", line 3
    using namespace std;
          ^^^^^^^^^
SyntaxError: invalid syntax