結果
問題 | No.2 素因数ゲーム |
ユーザー | penqen |
提出日時 | 2021-02-07 15:46:30 |
言語 | Elixir (1.16.2) |
結果 |
AC
|
実行時間 | 574 ms / 5,000 ms |
コード長 | 2,002 bytes |
コンパイル時間 | 955 ms |
コンパイル使用メモリ | 66,320 KB |
実行使用メモリ | 56,124 KB |
最終ジャッジ日時 | 2024-06-10 00:27:45 |
合計ジャッジ時間 | 19,628 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 562 ms
54,216 KB |
testcase_01 | AC | 545 ms
54,248 KB |
testcase_02 | AC | 534 ms
54,648 KB |
testcase_03 | AC | 552 ms
54,820 KB |
testcase_04 | AC | 543 ms
54,100 KB |
testcase_05 | AC | 550 ms
54,112 KB |
testcase_06 | AC | 564 ms
53,988 KB |
testcase_07 | AC | 535 ms
56,124 KB |
testcase_08 | AC | 528 ms
53,992 KB |
testcase_09 | AC | 545 ms
54,576 KB |
testcase_10 | AC | 562 ms
54,252 KB |
testcase_11 | AC | 570 ms
54,428 KB |
testcase_12 | AC | 568 ms
53,680 KB |
testcase_13 | AC | 568 ms
54,132 KB |
testcase_14 | AC | 566 ms
53,864 KB |
testcase_15 | AC | 545 ms
54,332 KB |
testcase_16 | AC | 547 ms
54,300 KB |
testcase_17 | AC | 540 ms
53,988 KB |
testcase_18 | AC | 530 ms
53,724 KB |
testcase_19 | AC | 542 ms
54,140 KB |
testcase_20 | AC | 574 ms
53,728 KB |
testcase_21 | AC | 570 ms
53,752 KB |
testcase_22 | AC | 546 ms
54,604 KB |
testcase_23 | AC | 570 ms
54,384 KB |
testcase_24 | AC | 541 ms
54,260 KB |
testcase_25 | AC | 554 ms
53,996 KB |
testcase_26 | AC | 541 ms
53,992 KB |
testcase_27 | AC | 542 ms
54,336 KB |
testcase_28 | AC | 530 ms
54,328 KB |
testcase_29 | AC | 528 ms
54,128 KB |
testcase_30 | AC | 565 ms
54,992 KB |
コンパイルメッセージ
warning: ^^^ is deprecated. It is typically used as xor but it has the wrong precedence, use Bitwise.bxor/2 instead │ 73 │ acc ^^^ number │ ~ │ └─ Main.exs:73:13 warning: use Bitwise is deprecated. import Bitwise instead │ 2 │ use Bitwise, only_operators: true │ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ │ └─ Main.exs:2: Main (module)
ソースコード
defmodule Main do use Bitwise, only_operators: true defmodule Factorization do defstruct value: 2 def next(factor \\ %__MODULE__{value: 2}) def next(%__MODULE__{value: 2}), do: %__MODULE__{value: 3} def next(%__MODULE__{value: n}) do if is_prime(n + 2) do %__MODULE__{value: n + 2} else next(%__MODULE__{value: n + 2}) end end def is_prime(n) def is_prime(n) when n < 2, do: false def is_prime(2), do: true def is_prime(3), do: true def is_prime(n) when 3 < n do if rem(n, 2) == 0 do false else is_prime(n, 3) end end defp is_prime(n, i) when i * i <= n do if rem(n, i) == 0 do false else is_prime(n, i + 2) end end defp is_prime(_, _), do: true def to_list(n, factor \\ %Factorization{}, combinations \\ []) def to_list(1, _, combinations), do: combinations def to_list(n, %{value: prime} = factor, combinations) do if Factorization.is_prime(n) do [{n, 1} | combinations] else if rem(n, prime) == 0 do {n0, base} = to_exponent(n, prime) to_list(n0, Factorization.next(factor), [{prime, base} | combinations]) else to_list(n, Factorization.next(factor), combinations) end end end defp to_exponent(n, factor, count \\ 0) defp to_exponent(n, factor, count) do if rem(n, factor) == 0 do to_exponent(div(n, factor), factor, count + 1) else {n, count} end end end def main do IO.read(:line) |> String.trim() |> String.to_integer() |> solve() |> IO.puts() end def solve(n) when 2 <= n and n <= 100_000_000 do n |> Factorization.to_list() |> Enum.reduce(nil, fn {_prime_number, number}, nil -> number {_prime_number, number}, acc -> acc ^^^ number end) |> Kernel.==(0) |> if do "Bob" else "Alice" end end end