結果

問題 No.109 N! mod M
ユーザー cielciel
提出日時 2015-10-31 23:10:49
言語 PyPy2
(7.3.15)
結果
WA  
実行時間 -
コード長 287 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 77,968 KB
実行使用メモリ 78,888 KB
最終ジャッジ日時 2023-10-11 07:34:51
合計ジャッジ時間 1,973 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
78,744 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 79 ms
78,540 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 RE -
testcase_08 AC 85 ms
78,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/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=pow(m-1,n-2,m)
	print(a)
0