結果

問題 No.816 Beautiful tuples
ユーザー nao22bnao22b
提出日時 2019-04-19 21:40:28
言語 Elixir
(1.16.2)
結果
TLE  
実行時間 -
コード長 659 bytes
コンパイル時間 1,028 ms
コンパイル使用メモリ 57,772 KB
実行使用メモリ 49,380 KB
最終ジャッジ日時 2023-08-29 23:20:09
合計ジャッジ時間 12,484 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 606 ms
49,296 KB
testcase_01 AC 610 ms
49,380 KB
testcase_02 AC 1,154 ms
48,640 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

0