結果

問題 No.2051 Divide
コンテスト
ユーザー norioc
提出日時 2024-08-12 04:15:01
言語 Elixir
(1.19.5)
コンパイル:
elixirc _filename_
実行:
elixir -e Main.main
結果
AC  
実行時間 327 ms / 2,000 ms
コード長 668 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 979 ms
コンパイル使用メモリ 76,628 KB
実行使用メモリ 63,484 KB
最終ジャッジ日時 2026-04-03 20:58:49
合計ジャッジ時間 9,851 ms
ジャッジサーバーID
(参考情報)
judge5_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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