結果

問題 No.816 Beautiful tuples
ユーザー ganariyaganariya
提出日時 2019-04-20 09:13:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 43 ms / 1,500 ms
コード長 683 bytes
コンパイル時間 603 ms
コンパイル使用メモリ 81,688 KB
実行使用メモリ 59,388 KB
最終ジャッジ日時 2023-10-25 22:06:48
合計ジャッジ時間 1,979 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,528 KB
testcase_01 AC 40 ms
53,528 KB
testcase_02 AC 41 ms
59,388 KB
testcase_03 AC 41 ms
59,388 KB
testcase_04 AC 42 ms
59,388 KB
testcase_05 AC 43 ms
59,388 KB
testcase_06 AC 42 ms
59,388 KB
testcase_07 AC 41 ms
59,388 KB
testcase_08 AC 41 ms
59,388 KB
testcase_09 AC 41 ms
59,388 KB
testcase_10 AC 42 ms
59,388 KB
testcase_11 AC 41 ms
59,388 KB
testcase_12 AC 42 ms
59,388 KB
testcase_13 AC 42 ms
59,388 KB
testcase_14 AC 38 ms
53,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-

import sys
import copy

sys.setrecursionlimit(1000000)


# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(^~^ 」 ∠)_~~~~~~~~~~~~~~~~~~~~~

def get_divisors(x):
    ret = []
    i = 1
    while i * i <= x:
        if x % i == 0:
            ret.append(i)
            if x // i != i:
                ret.append(x // i)
        i += 1
    ret = sorted(ret)
    return ret


A, B = map(int, input().split())

divisors = get_divisors(A + B)

ans = 100000000000000000000

for C in divisors:
    if (A + C) % B == 0 and (B + C) % A == 0 and A != B and B != C and A != C:
        ans = min(ans, C)


print(ans if ans != 100000000000000000000 else -1)
0