結果
問題 | No.816 Beautiful tuples |
ユーザー |
![]() |
提出日時 | 2019-04-19 21:36:11 |
言語 | Elixir (1.18.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 636 bytes |
コンパイル時間 | 1,169 ms |
コンパイル使用メモリ | 63,024 KB |
実行使用メモリ | 56,276 KB |
最終ジャッジ日時 | 2024-12-31 02:49:01 |
合計ジャッジ時間 | 12,017 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 8 WA * 7 |
ソースコード
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