結果

問題 No.816 Beautiful tuples
ユーザー nao22bnao22b
提出日時 2019-04-19 22:00:37
言語 Elixir
(1.16.2)
結果
AC  
実行時間 640 ms / 1,500 ms
コード長 782 bytes
コンパイル時間 1,089 ms
コンパイル使用メモリ 55,668 KB
実行使用メモリ 51,292 KB
最終ジャッジ日時 2023-08-29 23:19:45
合計ジャッジ時間 12,223 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 621 ms
49,384 KB
testcase_01 AC 628 ms
49,244 KB
testcase_02 AC 629 ms
49,272 KB
testcase_03 AC 622 ms
49,352 KB
testcase_04 AC 628 ms
50,304 KB
testcase_05 AC 640 ms
49,844 KB
testcase_06 AC 625 ms
49,256 KB
testcase_07 AC 626 ms
49,392 KB
testcase_08 AC 632 ms
49,268 KB
testcase_09 AC 633 ms
49,292 KB
testcase_10 AC 640 ms
49,236 KB
testcase_11 AC 635 ms
49,264 KB
testcase_12 AC 626 ms
51,292 KB
testcase_13 AC 629 ms
49,208 KB
testcase_14 AC 625 ms
49,820 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