結果

問題 No.109 N! mod M
ユーザー %20%20
提出日時 2017-07-02 16:44:51
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 284 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2024-04-15 12:35:57
合計ジャッジ時間 3,357 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
12,160 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 112 ms
12,288 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 117 ms
12,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require'prime'
T=gets.to_i
T.times do
	n,m=gets.split.map &:to_i
	if n<m && m.prime?
		r=m-1
		(m-1).downto(n+1).each do|i|
			r*=i
			r%=m
		end
		p `python -c'print pow(#{r},#{m-2},#{m})'`.to_i
	elsif n<=10**5
		r=1
		1.upto(n)do|i|
			r*=i
			r%=m
		end
		p r
	else
		p 0
	end
end
0