結果

問題 No.816 Beautiful tuples
コンテスト
ユーザー 学ぶマン
提出日時 2025-11-04 20:57:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 39 ms / 1,500 ms
コード長 539 bytes
コンパイル時間 528 ms
コンパイル使用メモリ 82,840 KB
実行使用メモリ 59,640 KB
最終ジャッジ日時 2025-11-04 20:57:13
合計ジャッジ時間 1,878 ms
ジャッジサーバーID
(参考情報)
judge7 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

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

# a + b = 0 mod c
# c は a+b の約数である
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]

divs = make_divisors(A + B)

for c in divs:
    if c == A or c == B:
        continue
    if (B + c)%A == 0 and (c + A)%B == 0:
        exit(print(c))

print(-1)
0