結果

問題 No.500 階乗電卓
ユーザー gemmarogemmaro
提出日時 2020-05-13 09:04:57
言語 Elixir
(1.16.2)
結果
AC  
実行時間 642 ms / 2,000 ms
コード長 603 bytes
コンパイル時間 1,066 ms
コンパイル使用メモリ 55,384 KB
実行使用メモリ 50,512 KB
最終ジャッジ日時 2023-08-30 00:48:20
合計ジャッジ時間 17,230 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 630 ms
49,292 KB
testcase_01 AC 629 ms
49,348 KB
testcase_02 AC 642 ms
49,812 KB
testcase_03 AC 627 ms
50,000 KB
testcase_04 AC 626 ms
49,396 KB
testcase_05 AC 632 ms
49,832 KB
testcase_06 AC 633 ms
49,372 KB
testcase_07 AC 627 ms
49,992 KB
testcase_08 AC 623 ms
49,296 KB
testcase_09 AC 622 ms
49,840 KB
testcase_10 AC 640 ms
49,420 KB
testcase_11 AC 636 ms
49,172 KB
testcase_12 AC 636 ms
49,232 KB
testcase_13 AC 635 ms
50,512 KB
testcase_14 AC 635 ms
49,884 KB
testcase_15 AC 634 ms
49,468 KB
testcase_16 AC 626 ms
49,408 KB
testcase_17 AC 632 ms
49,320 KB
testcase_18 AC 627 ms
49,264 KB
testcase_19 AC 626 ms
49,804 KB
testcase_20 AC 627 ms
49,736 KB
testcase_21 AC 622 ms
49,968 KB
testcase_22 AC 629 ms
50,184 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 < 60 -> 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