結果

問題 No.816 Beautiful tuples
ユーザー kekurekekure
提出日時 2019-07-08 00:22:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 44 ms / 1,500 ms
コード長 437 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 57,984 KB
最終ジャッジ日時 2024-04-15 19:07:58
合計ジャッジ時間 1,563 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,224 KB
testcase_01 AC 40 ms
51,968 KB
testcase_02 AC 42 ms
57,728 KB
testcase_03 AC 42 ms
57,344 KB
testcase_04 AC 41 ms
57,728 KB
testcase_05 AC 43 ms
57,984 KB
testcase_06 AC 43 ms
57,728 KB
testcase_07 AC 42 ms
57,728 KB
testcase_08 AC 43 ms
57,856 KB
testcase_09 AC 43 ms
57,984 KB
testcase_10 AC 44 ms
57,728 KB
testcase_11 AC 43 ms
57,344 KB
testcase_12 AC 43 ms
57,640 KB
testcase_13 AC 44 ms
57,728 KB
testcase_14 AC 39 ms
52,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

A, B = map(int, input().split())
ApB = A + B
divisor = [1, ApB]
index = 1
limit = int(math.sqrt(ApB))
for i in range(2, limit + 1):
    if ApB % i == 0 and i != A and i != B:
        divisor.append(i)
        N = ApB // i
        if N != i and N != A and N != B:
            divisor.append(N)
divisor.sort()

for C in divisor:
    if (A + C) % B == 0 and (B + C) % A == 0:
        print(C)
        break
else:
    print(-1)
0