結果

問題 No.816 Beautiful tuples
ユーザー ganariyaganariya
提出日時 2019-04-20 09:13:40
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 33 ms / 1,500 ms
コード長 683 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 10,200 KB
最終ジャッジ日時 2023-10-25 22:06:45
合計ジャッジ時間 1,145 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,200 KB
testcase_01 AC 28 ms
10,200 KB
testcase_02 AC 30 ms
10,200 KB
testcase_03 AC 31 ms
10,200 KB
testcase_04 AC 28 ms
10,200 KB
testcase_05 AC 33 ms
10,200 KB
testcase_06 AC 28 ms
10,200 KB
testcase_07 AC 30 ms
10,200 KB
testcase_08 AC 29 ms
10,200 KB
testcase_09 AC 28 ms
10,200 KB
testcase_10 AC 30 ms
10,200 KB
testcase_11 AC 31 ms
10,200 KB
testcase_12 AC 32 ms
10,200 KB
testcase_13 AC 30 ms
10,200 KB
testcase_14 AC 27 ms
10,200 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