結果

問題 No.1168 Digit Sum Sequence
ユーザー penqenpenqen
提出日時 2020-12-15 20:51:51
言語 Elixir
(1.16.2)
結果
AC  
実行時間 641 ms / 2,000 ms
コード長 595 bytes
コンパイル時間 1,010 ms
コンパイル使用メモリ 54,704 KB
実行使用メモリ 50,420 KB
最終ジャッジ日時 2023-08-30 01:01:09
合計ジャッジ時間 23,160 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 627 ms
49,628 KB
testcase_01 AC 628 ms
49,620 KB
testcase_02 AC 631 ms
49,256 KB
testcase_03 AC 631 ms
49,256 KB
testcase_04 AC 631 ms
49,576 KB
testcase_05 AC 640 ms
49,356 KB
testcase_06 AC 626 ms
49,612 KB
testcase_07 AC 629 ms
49,772 KB
testcase_08 AC 637 ms
49,116 KB
testcase_09 AC 630 ms
49,268 KB
testcase_10 AC 629 ms
49,372 KB
testcase_11 AC 636 ms
49,292 KB
testcase_12 AC 636 ms
50,316 KB
testcase_13 AC 628 ms
49,656 KB
testcase_14 AC 631 ms
49,496 KB
testcase_15 AC 633 ms
50,056 KB
testcase_16 AC 630 ms
50,420 KB
testcase_17 AC 623 ms
49,532 KB
testcase_18 AC 631 ms
49,468 KB
testcase_19 AC 631 ms
50,112 KB
testcase_20 AC 636 ms
49,456 KB
testcase_21 AC 631 ms
49,360 KB
testcase_22 AC 620 ms
49,568 KB
testcase_23 AC 617 ms
49,376 KB
testcase_24 AC 629 ms
49,496 KB
testcase_25 AC 619 ms
49,588 KB
testcase_26 AC 636 ms
50,060 KB
testcase_27 AC 630 ms
49,500 KB
testcase_28 AC 641 ms
49,400 KB
testcase_29 AC 632 ms
50,032 KB
testcase_30 AC 607 ms
50,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

  def solve(n), do: solve(n, 1)

  def solve(n, _) when n < 10, do: n
  def solve(n, 100), do: n
  def solve(n, i) when 1 <= n and n <= 1_000_000_000 do
    num_of_digits = n |> to_string() |> String.length()
    n |> a_i(num_of_digits) |> solve(i + 1)
  end
  def solve(_, _), do: :error

  def a_i(n, 0), do: n
  def a_i(n, num_of_digits) do
    base = :math.pow(10, num_of_digits) |> round()
    div(n, base) + a_i(rem(n, base), num_of_digits - 1)
  end

end
0