結果
| 問題 | No.816 Beautiful tuples | 
| コンテスト | |
| ユーザー |  brthyyjp | 
| 提出日時 | 2020-06-19 16:51:42 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 40 ms / 1,500 ms | 
| コード長 | 436 bytes | 
| コンパイル時間 | 175 ms | 
| コンパイル使用メモリ | 82,176 KB | 
| 実行使用メモリ | 57,856 KB | 
| 最終ジャッジ日時 | 2024-07-03 13:28:35 | 
| 合計ジャッジ時間 | 1,380 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 15 | 
ソースコード
a, b = map(int, input().split())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
d = make_divisors(a+b)
for c in d:
    if (a+c)%b == 0 and (b+c)%a == 0:
        if a != c and b != c:
            print(c)
            exit()
else:
    print(-1)
            
            
            
        