結果
| 問題 |
No.816 Beautiful tuples
|
| コンテスト | |
| ユーザー |
nao22b
|
| 提出日時 | 2019-04-19 21:40:28 |
| 言語 | Elixir (1.18.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 659 bytes |
| コンパイル時間 | 1,067 ms |
| コンパイル使用メモリ | 63,008 KB |
| 実行使用メモリ | 69,704 KB |
| 最終ジャッジ日時 | 2024-12-31 02:50:19 |
| 合計ジャッジ時間 | 36,655 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 TLE * 11 |
ソースコード
defmodule Main do
def divisors(n, curr) when curr > n, do: []
def divisors(n, curr) when rem(n, curr) == 0, do: [curr, div(n, curr)] ++ divisors(n, 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 && a != x && b != x -> 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
nao22b