結果

問題 No.816 Beautiful tuples
ユーザー betrue12betrue12
提出日時 2019-04-19 21:27:49
言語 Ruby
(3.1.1p18 )
結果
AC  
実行時間 77 ms / 1,500 ms
コード長 300 bytes
コンパイル時間 245 ms
使用メモリ 13,964 KB
最終ジャッジ日時 2022-11-22 05:47:36
合計ジャッジ時間 2,932 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 75 ms
13,696 KB
testcase_01 AC 74 ms
13,796 KB
testcase_02 AC 73 ms
13,772 KB
testcase_03 AC 73 ms
13,712 KB
testcase_04 AC 74 ms
13,720 KB
testcase_05 AC 77 ms
13,796 KB
testcase_06 AC 73 ms
13,796 KB
testcase_07 AC 73 ms
13,800 KB
testcase_08 AC 74 ms
13,964 KB
testcase_09 AC 73 ms
13,772 KB
testcase_10 AC 75 ms
13,932 KB
testcase_11 AC 74 ms
13,824 KB
testcase_12 AC 77 ms
13,828 KB
testcase_13 AC 77 ms
13,708 KB
testcase_14 AC 73 ms
13,712 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:17: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

a, b = gets.split.map(&:to_i)

s = a+b
ans = []
(1..s).each do |i|
    break if i*i > s
    next if s % i > 0
    [i, s/i].each do |c|
        if c != a && c != b && (b+c) % a == 0 && (c+a) % b == 0
            ans.push(c)
        end
    end
end
if ans.size > 0
    puts ans.min
else
    puts -1
end
0