結果

問題 No.816 Beautiful tuples
ユーザー rlangevinrlangevin
提出日時 2023-01-03 17:06:51
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 386 bytes
コンパイル時間 786 ms
コンパイル使用メモリ 86,752 KB
実行使用メモリ 75,456 KB
最終ジャッジ日時 2023-08-18 00:41:53
合計ジャッジ時間 2,804 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 72 ms
71,172 KB
testcase_02 AC 76 ms
75,032 KB
testcase_03 WA -
testcase_04 AC 78 ms
75,456 KB
testcase_05 AC 76 ms
75,180 KB
testcase_06 AC 75 ms
75,144 KB
testcase_07 AC 74 ms
75,176 KB
testcase_08 AC 75 ms
75,288 KB
testcase_09 AC 74 ms
75,228 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 76 ms
75,336 KB
testcase_13 AC 76 ms
75,232 KB
testcase_14 AC 72 ms
71,168 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:
        ans = min(ans, d)
print(ans) if ans != inf else print(-1)
0