結果

問題 No.3357 eの部分和 mod 素数
コンテスト
ユーザー miya145592
提出日時 2025-11-15 00:44:01
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 438 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 82,648 KB
実行使用メモリ 848,696 KB
最終ジャッジ日時 2025-11-15 00:44:08
合計ジャッジ時間 4,979 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 MLE * 1 -- * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
P = int(input())
inverse = [0, 1]
fact = [1, 1]
fact_inv = [1, 1]
bunbo = 1
for i in range(2, P):
    inverse.append( ( -inverse[P % i] * (P//i) ) % P )
    fact.append(fact[-1]*i%P)
    fact_inv.append(fact_inv[-1] * inverse[-1] % P)
    bunbo *= fact[-1]
    bunbo %= P
bunsi = 0
for i in range(P):
    bunsi += bunbo * fact_inv[i] % P
    bunsi %= P
ans = bunsi * pow(bunbo, P-2, P) % P
print(ans)
0