結果

問題 No.816 Beautiful tuples
ユーザー MineMine
提出日時 2020-09-09 16:12:58
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 38 ms / 1,500 ms
コード長 512 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-12-15 07:59:05
合計ジャッジ時間 1,310 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

a, b = map(int, input().split())
m = make_divisors(a+b)
for c in m:
    if (a+b)%c == 0 and (b+c)%a == 0 and (c+a)%b == 0 and a!=c and b!=c:
        print(c)
        exit()
print(-1)
0