結果
| 問題 | No.816 Beautiful tuples | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-04-20 09:13:40 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 36 ms / 1,500 ms | 
| コード長 | 683 bytes | 
| コンパイル時間 | 287 ms | 
| コンパイル使用メモリ | 12,544 KB | 
| 実行使用メモリ | 11,008 KB | 
| 最終ジャッジ日時 | 2024-09-25 06:25:59 | 
| 合計ジャッジ時間 | 1,221 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 15 | 
ソースコード
# -*- 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)
            
            
            
        