結果
問題 | No.109 N! mod M |
ユーザー | ciel |
提出日時 | 2015-10-31 23:16:15 |
言語 | PyPy2 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 294 bytes |
コンパイル時間 | 143 ms |
コンパイル使用メモリ | 77,600 KB |
実行使用メモリ | 340,564 KB |
最終ジャッジ日時 | 2023-10-11 07:35:03 |
合計ジャッジ時間 | 7,567 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 82 ms
340,564 KB |
testcase_01 | AC | 449 ms
89,008 KB |
testcase_02 | AC | 156 ms
79,992 KB |
testcase_03 | AC | 82 ms
78,308 KB |
testcase_04 | TLE | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
ソースコード
#!/usr/bin/python for _ in range(input()): n,m=map(int,raw_input().split()) a=0 b=1 while b*-~b<=m: b+=1 if m%b<1: if n<b+m/b: a=1 while n: a=a*n%m n-=1 break else: if n<m: b=1 n+=1 while n<m: b=b*n%m n+=1 a=(m-1)*b**max(n-2,0)%m print(a)