結果

問題 No.109 N! mod M
ユーザー cielciel
提出日時 2015-11-01 01:05:00
言語 Ruby
(3.3.0)
結果
AC  
実行時間 813 ms / 5,000 ms
コード長 234 bytes
コンパイル時間 55 ms
コンパイル使用メモリ 11,380 KB
実行使用メモリ 15,336 KB
最終ジャッジ日時 2023-09-04 05:32:21
合計ジャッジ時間 2,829 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
15,316 KB
testcase_01 AC 139 ms
15,232 KB
testcase_02 AC 158 ms
15,040 KB
testcase_03 AC 98 ms
15,136 KB
testcase_04 AC 104 ms
15,336 KB
testcase_05 AC 813 ms
15,256 KB
testcase_06 AC 417 ms
15,136 KB
testcase_07 AC 132 ms
15,136 KB
testcase_08 AC 112 ms
15,120 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

gets;$<.map{|e|	
	n,m=e.split.map &:to_i
	a=0
	if (2..Math.sqrt(m)).each{|b|
		(n.downto(a=1){|n|a=a*n%m}if n<b+m/b;break) if m%b<1
	}&&n<m
		(n+1..m-b=1).each{|n|b=b*n%m};a=1+n=m-2;(a=a*b%m if n%2>0;b=b*b%m;n/=2)while n>0
	end
	p a
}
0