結果
問題 | No.109 N! mod M |
ユーザー | ciel |
提出日時 | 2015-11-01 00:53:18 |
言語 | Ruby (3.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 285 bytes |
コンパイル時間 | 150 ms |
コンパイル使用メモリ | 11,320 KB |
実行使用メモリ | 15,588 KB |
最終ジャッジ日時 | 2023-10-11 07:35:39 |
合計ジャッジ時間 | 1,769 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 90 ms
15,164 KB |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | AC | 100 ms
15,168 KB |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | AC | 119 ms
15,276 KB |
コンパイルメッセージ
Syntax OK
ソースコード
#!/usr/bin/ruby gets.to_i.times{ n,m=gets.split.map(&:to_i) a=0 if (2..Math.sqrt(m)).each{|b| if m%b<1 n.downto(a=1){|n|a=a*n%m} if n<b+m/b break end } && n<m (n+b=1..m-1).each{|n|b=b*n%m} a=1+n=m-2 while n>0 a=a*b%m if n%2>0 b=b*b%m n/=2 end end p a }