結果

問題 No.816 Beautiful tuples
ユーザー _KingdomOfMoray
提出日時 2020-01-10 18:56:19
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 37 ms / 1,500 ms
コード長 780 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-11-23 22:14:51
合計ジャッジ時間 1,436 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

def divisor_list_calc(n):
    divisor_list = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisor_list.append(i)
            if n // i != i:
                # 誤って、divisor_list.append(n)にしてた
                divisor_list.append(n // i)
    return divisor_list
            
a, b = map(int,input().split())
c_list = divisor_list_calc(a + b)
res = None
res_list = []

for i in range(len(c_list)):
    cond_list = []
    
    cond_list.append((b + c_list[i]) % a == 0)
    cond_list.append((a + c_list[i]) % b == 0)
    cond_list.append(a != c_list[i])
    cond_list.append(b != c_list[i])
    
    if all(cond_list):
        res_list.append(c_list[i])

if len(res_list) == 0:
    res = -1
else:
    res = min(res_list)
    
print(res)
0