結果
問題 | No.816 Beautiful tuples |
ユーザー | nao22b |
提出日時 | 2019-04-19 21:36:11 |
言語 | Elixir (1.16.2) |
結果 |
WA
|
実行時間 | - |
コード長 | 636 bytes |
コンパイル時間 | 1,233 ms |
コンパイル使用メモリ | 55,552 KB |
実行使用メモリ | 50,416 KB |
最終ジャッジ日時 | 2023-08-29 23:19:31 |
合計ジャッジ時間 | 14,030 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 632 ms
49,476 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 940 ms
49,616 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 644 ms
49,776 KB |
testcase_08 | AC | 666 ms
49,424 KB |
testcase_09 | AC | 795 ms
49,232 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 665 ms
49,404 KB |
testcase_13 | AC | 629 ms
49,840 KB |
testcase_14 | AC | 625 ms
49,400 KB |
ソースコード
defmodule Main do def divisors(n, curr) when curr > n, do: [] def divisors(n, curr) when rem(n, curr) == 0, do: [curr] ++ divisors(div(n, curr), curr + 1) def divisors(n, curr), do: divisors(n, curr + 1) def find([], _, _), do: -1 def find([x|xs], a, b) do cond do rem(x + a, b) == 0 && rem(x + b, a) == 0 -> x true -> find(xs, a, b) end end def solve(a, b) do divisors(a + b, 1) |> find(a, b) end def main do [a, b] = IO.gets("") |> String.trim |> String.split |> Enum.map(&String.to_integer/1) solve(a, b) |> IO.puts end end