QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#412586#6736. Alice and BobXiaoretaWCompile Error//C++201.4kb2024-05-16 16:19:262024-05-16 16:19:26

Judging History

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

  • [2024-05-16 16:19:26]
  • 评测
  • [2024-05-16 16:19:26]
  • 提交

answer

#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 998244353;
const int N = 1e7 + 1;
int fact[N], infact[N];
int power(int a, int b) {
    int res = 1;
    for (; b; b /= 2, a = 1LL * a * a % P) {
        if (b % 2) {
            res = 1LL * res * a % P;
        }
    }
    return res;
}
void Init(int n) {
    fact[0] = 1;
    infact[0] = 1;
    for (int i = 1; i <= n; i++) {
        fact[i] = 1ll * fact[i - 1] * i % mod;
        infact[i] = 1ll * infact[i - 1] * power(i, mod - 2) % mod;
    }
}
int C(int a, int b) {
    return 1ll * fact[a] * infact[b] % mod * infact[a - b] % mod;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);    
    
    int n; cin >> n;
    Init(n);
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i - 1 <= n - i) {
            // ans = (ans + 1ll * fact[i - 1] * C(n - i, i - 1) % mod * fact[n - i] % mod) % mod;
            // ll res = 1;
            // for (int j = n - 2 * i + 2; j <= n - i; j++) res = res * j % mod;
            // cout << "range: " << n - 2 * i + 2 << ' ' << n - i << '\n';
            // ans = (ans + 1ll * fact[n - i] * res % mod) % mod;
            ans = (ans + 1ll * fact[n - i] * fact[n - i] % mod * infact[n - 2 * i + 1] % mod) % mod;
        } else break;
    }
    cout << ans << '\n';

    return 0;
}

Details

answer.code: In function ‘int power(int, int)’:
answer.code:10:41: error: ‘P’ was not declared in this scope
   10 |     for (; b; b /= 2, a = 1LL * a * a % P) {
      |                                         ^