結果

問題 No.500 階乗電卓
ユーザー gemmarogemmaro
提出日時 2020-05-13 09:01:16
言語 Elixir
(1.16.2)
結果
WA  
実行時間 -
コード長 603 bytes
コンパイル時間 1,256 ms
コンパイル使用メモリ 54,776 KB
実行使用メモリ 49,968 KB
最終ジャッジ日時 2023-08-30 00:47:55
合計ジャッジ時間 17,535 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 614 ms
49,280 KB
testcase_01 AC 621 ms
49,248 KB
testcase_02 AC 625 ms
49,392 KB
testcase_03 AC 624 ms
49,516 KB
testcase_04 AC 632 ms
49,316 KB
testcase_05 AC 633 ms
49,348 KB
testcase_06 AC 636 ms
49,228 KB
testcase_07 AC 625 ms
49,184 KB
testcase_08 AC 635 ms
49,832 KB
testcase_09 AC 629 ms
49,336 KB
testcase_10 AC 628 ms
49,944 KB
testcase_11 AC 629 ms
49,432 KB
testcase_12 AC 628 ms
49,168 KB
testcase_13 AC 630 ms
49,952 KB
testcase_14 AC 635 ms
49,216 KB
testcase_15 WA -
testcase_16 AC 628 ms
49,268 KB
testcase_17 AC 630 ms
49,308 KB
testcase_18 AC 650 ms
49,200 KB
testcase_19 AC 627 ms
49,332 KB
testcase_20 AC 637 ms
49,968 KB
testcase_21 AC 632 ms
49,864 KB
testcase_22 AC 636 ms
49,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

defmodule Main do
  @mask 1_000_000_000_000

  def main do
    IO.read(:line) |> String.trim() |> String.to_integer() |> solve |> IO.puts()
  end

  def solve(n) do
    cond do
      n < 40 -> solve_rec(n, 1, false)
      :else -> "000000000000"
    end
  end

  def solve_rec(1, r, pad) do
    cond do
      pad -> r |> to_string |> String.pad_leading(12, "0")
      :else -> r
    end
  end

  def solve_rec(n, r, pad) do
    tmp = n * r
    a = tmp |> div(@mask)

    cond do
      a == 0 -> solve_rec(n - 1, tmp, pad || false)
      :else -> solve_rec(n - 1, tmp - a * @mask, true)
    end
  end
end
0