結果

問題 No.816 Beautiful tuples
ユーザー alexara1123alexara1123
提出日時 2019-09-21 01:56:40
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 79 ms / 1,500 ms
コード長 607 bytes
コンパイル時間 1,498 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 75,940 KB
最終ジャッジ日時 2023-10-13 10:33:09
合計ジャッジ時間 2,862 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,644 KB
testcase_01 AC 73 ms
71,568 KB
testcase_02 AC 76 ms
75,940 KB
testcase_03 AC 75 ms
75,876 KB
testcase_04 AC 76 ms
75,752 KB
testcase_05 AC 76 ms
75,836 KB
testcase_06 AC 79 ms
75,784 KB
testcase_07 AC 76 ms
75,680 KB
testcase_08 AC 77 ms
75,880 KB
testcase_09 AC 78 ms
75,656 KB
testcase_10 AC 77 ms
75,656 KB
testcase_11 AC 77 ms
75,752 KB
testcase_12 AC 78 ms
75,696 KB
testcase_13 AC 78 ms
75,880 KB
testcase_14 AC 72 ms
71,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


def main():
    a, b = map(int, input().split())
    l = make_divisors(a + b)
    ans = float("inf")
    for c in l:
        if a == c or b == c:
            continue
        if (b + c) % a == 0 and (a + c) % b == 0:
            ans = min(ans, c)
    if ans == float("inf"):
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()
0