結果
| 問題 |
No.3357 eの部分和 mod 素数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-15 19:12:51 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3,668 ms / 10,000 ms |
| コード長 | 574 bytes |
| コンパイル時間 | 2,878 ms |
| コンパイル使用メモリ | 275,592 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-11-15 19:13:42 |
| 合計ジャッジ時間 | 47,168 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)
ll modpow(ll a, ll n, ll m) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * a % m;
a = a * a % m;
n >>= 1;
}
return res;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
ll P;
cin >> P;
ll frac = 1;
rep(i, 2, P) frac = (frac * (ll)i) % P;
frac = modpow(frac, P - 2, P);
ll ans = 0;
for (ll t = P - 1; t >= 0; --t) {
ans = (ans + frac) % P;
frac = (frac * t) % P;
}
cout << ans << '\n';
}