結果

問題 No.816 Beautiful tuples
ユーザー nao22bnao22b
提出日時 2019-04-19 22:00:37
言語 Elixir
(1.7.4)
結果
AC  
実行時間 468 ms / 1,500 ms
コード長 782 bytes
コンパイル時間 581 ms
使用メモリ 49,256 KB
最終ジャッジ日時 2023-01-16 16:22:06
合計ジャッジ時間 8,597 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 448 ms
49,248 KB
testcase_01 AC 442 ms
49,104 KB
testcase_02 AC 468 ms
49,148 KB
testcase_03 AC 453 ms
48,900 KB
testcase_04 AC 446 ms
49,256 KB
testcase_05 AC 442 ms
48,708 KB
testcase_06 AC 442 ms
49,120 KB
testcase_07 AC 440 ms
49,016 KB
testcase_08 AC 446 ms
49,092 KB
testcase_09 AC 439 ms
49,028 KB
testcase_10 AC 434 ms
49,112 KB
testcase_11 AC 439 ms
49,072 KB
testcase_12 AC 432 ms
49,180 KB
testcase_13 AC 439 ms
49,092 KB
testcase_14 AC 458 ms
49,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

defmodule Main do

    def is_answer(a, b, _) when (a == b), do: false
    def is_answer(a, _, c) when (a == c), do: false
    def is_answer(_, b, c) when (b == c), do: false
    def is_answer(a, b, c) do
        r1 = rem(a + b, c)
        r2 = rem(a + c, b)
        r3 = rem(b + c, a)
        r1 == 0 && r2 == 0 && r3 == 0
    end

    def solve(a, b, n) do
        r = rem(a + b, n)
        d2 = div(a + b, n)
        cond do
            is_answer(a, b, a + b) -> (a + b)
            r == 0 && is_answer(a, b, d2) -> d2
            d2 < a - b || d2 < b - a -> -1
            true -> solve(a, b, n + 1)
        end
    end

    def main do
        [a, b] = IO.gets("") |> String.trim |> String.split |> Enum.map(&String.to_integer/1)
        solve(a, b, 1) |> IO.puts
    end
end

0