結果

問題 No.575 n! / m / m / m...
ユーザー char134217728char134217728
提出日時 2017-12-18 03:46:27
言語 Ruby
(3.2.2)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 468 bytes
コンパイル時間 562 ms
コンパイル使用メモリ 11,220 KB
実行使用メモリ 15,788 KB
最終ジャッジ日時 2023-08-22 05:21:44
合計ジャッジ時間 5,483 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
15,596 KB
testcase_01 AC 97 ms
15,780 KB
testcase_02 AC 95 ms
15,512 KB
testcase_03 AC 93 ms
15,656 KB
testcase_04 AC 93 ms
15,668 KB
testcase_05 AC 95 ms
15,788 KB
testcase_06 AC 92 ms
15,580 KB
testcase_07 AC 92 ms
15,668 KB
testcase_08 AC 92 ms
15,588 KB
testcase_09 AC 92 ms
15,344 KB
testcase_10 AC 94 ms
15,500 KB
testcase_11 AC 93 ms
15,584 KB
testcase_12 AC 94 ms
15,656 KB
testcase_13 AC 92 ms
15,580 KB
testcase_14 AC 93 ms
15,712 KB
testcase_15 AC 93 ms
15,596 KB
testcase_16 AC 92 ms
15,596 KB
testcase_17 AC 93 ms
15,784 KB
testcase_18 AC 95 ms
15,568 KB
testcase_19 AC 93 ms
15,544 KB
testcase_20 AC 91 ms
15,540 KB
testcase_21 AC 92 ms
15,524 KB
testcase_22 AC 92 ms
15,636 KB
testcase_23 AC 195 ms
15,588 KB
testcase_24 AC 92 ms
15,596 KB
testcase_25 AC 195 ms
15,772 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'
n, m = gets.split.map &:to_i
ans = if n > 10000
  c = Prime.prime_division(m).map{|pr, pow|
    cc = 0
    _pr = pr
    while _pr <= n do
      cc += n / _pr
      _pr *= pr
    end
    cc/pow
  }.min
  ln = Math.log(n)
  n * (ln - 1) + (ln + Math.log(Math::PI) + Math.log(2))/2 - Math.log(m) * c
else
  f = [*1..n].inject :*
  while f%m == 0
    f /= m
  end
  Math.log f
end
ans *= Math.log10(Math::E)
a = ans.floor
b = ans % 1
puts "#{10.0**b}e#{a}"
0