defmodule Main do
  require Integer

  def main do
    n = IO.gets("") |> String.trim() |> String.to_integer()

    div_game(n) |> IO.puts()
  end

  @doc """
  div_game

  ## Examples

      iex> DivGame.div_game(24)
      3
      iex> DivGame.div_game(64)
      3
      iex> DivGame.div_game(1)
      0
      iex> DivGame.div_game(1000000007)
      1
      iex> DivGame.div_game(997764507000)
      7

  """
  def div_game(n) do
    factors_for(n)
    |> Enum.frequencies()
    |> Map.values()
    |> Enum.map(&divide/1)
    |> Enum.sum()

  end

  defp divide(n) do
    Stream.iterate(1, & &1 + 1)
    |> Enum.reduce_while({n, 0}, fn i, {acc_n, acc_cnt} ->
      rem = acc_n - i
      if rem < 0, do: {:halt, {rem, acc_cnt}}, else: {:cont, {rem, acc_cnt + 1}}
    end)
    |> elem(1)
  end

  def factors_for(number) do
    factorize(number, 2, [])
  end

  defp factorize(number, factor, prime_factors) when number < factor do
    prime_factors
  end

  defp factorize(number, factor, prime_factors) when rem(number, factor) == 0 do
    [factor | factorize(div(number, factor), factor, prime_factors)]
  end

  defp factorize(number, factor, prime_factors) do
    factorize(number, factor + 1, prime_factors)
  end
end