結果

問題 No.816 Beautiful tuples
ユーザー rlangevinrlangevin
提出日時 2023-01-03 17:08:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 76 ms / 1,500 ms
コード長 408 bytes
コンパイル時間 418 ms
コンパイル使用メモリ 86,688 KB
実行使用メモリ 75,552 KB
最終ジャッジ日時 2023-08-18 00:41:58
合計ジャッジ時間 2,394 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,404 KB
testcase_01 AC 74 ms
70,964 KB
testcase_02 AC 75 ms
75,452 KB
testcase_03 AC 75 ms
75,408 KB
testcase_04 AC 75 ms
75,324 KB
testcase_05 AC 74 ms
75,444 KB
testcase_06 AC 75 ms
75,384 KB
testcase_07 AC 75 ms
75,372 KB
testcase_08 AC 75 ms
75,488 KB
testcase_09 AC 75 ms
75,300 KB
testcase_10 AC 76 ms
75,552 KB
testcase_11 AC 75 ms
75,360 KB
testcase_12 AC 75 ms
75,524 KB
testcase_13 AC 75 ms
75,328 KB
testcase_14 AC 72 ms
71,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def div(n):
    if n <= 0:
        return []
    S = set()
    i = 1
    while i * i <= n:
        if n % i == 0:
            S.add(i)
            S.add(n // i)
        i += 1
    return list(S)

A, B = map(int, input().split())
inf = 10 ** 18
ans = inf
for d in div(A + B):
    if (A + d) % B == 0 and (B + d) % A == 0 and d != A and d != B:
        ans = min(ans, d)
print(ans) if ans != inf else print(-1)
0