結果

問題 No.2051 Divide
ユーザー norioc
提出日時 2024-08-12 04:15:01
言語 Elixir
(1.18.1)
結果
AC  
実行時間 603 ms / 2,000 ms
コード長 668 bytes
コンパイル時間 1,938 ms
コンパイル使用メモリ 61,644 KB
実行使用メモリ 54,672 KB
最終ジャッジ日時 2024-08-12 04:15:20
合計ジャッジ時間 17,735 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

defmodule Main do
  def input, do: IO.read(:line) |> String.trim
  def ii, do: input() |> String.to_integer
  def li, do: input() |> String.split |> Enum.map(&String.to_integer/1)
  def yn(b), do: IO.puts(if b, do: "Yes", else: "No")

  def divisors(n) do
    _divisors(1, n) |> MapSet.new |> Enum.sort
  end

  defp _divisors(x, n) do
    cond do
      x * x > n -> []
      rem(n, x) == 0 -> [x, div(n, x) | _divisors(x+1, n)]
      true -> _divisors(x+1, n)
    end
  end

  def main do
    [a, b] = li()

    for d <- divisors(a), reduce: 0 do
      s ->
        s + case rem(d, b) do
          0 -> 1
          _ -> 0
        end
    end
    |> IO.puts
  end
end
0