結果

問題 No.109 N! mod M
ユーザー convexineqconvexineq
提出日時 2021-02-19 14:41:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 417 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 87,336 KB
実行使用メモリ 76,180 KB
最終ジャッジ日時 2023-10-14 08:59:00
合計ジャッジ時間 2,210 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
75,404 KB
testcase_01 AC 255 ms
74,972 KB
testcase_02 AC 171 ms
75,296 KB
testcase_03 WA -
testcase_04 AC 72 ms
75,696 KB
testcase_05 AC 205 ms
75,704 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(n,MOD):
    if n <= 1000000:
        r = 1
        for i in range(1,n+1):
            r *= i
            r %= MOD
        return r
    for i in range(2,int(MOD**0.5)+1):
        if MOD%i==0:
            return 0
    r = 1
    for i in range(n+1,MOD):
        r *= i
        r %= MOD
    return (-pow(r,MOD-2,MOD))%MOD

T = int(input())
for _ in range(T):
    n,MOD = map(int,input().split())
    print(f(n,MOD))
0