結果

問題 No.816 Beautiful tuples
ユーザー toyuzukotoyuzuko
提出日時 2020-04-28 16:45:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 30 ms / 1,500 ms
コード長 397 bytes
コンパイル時間 561 ms
コンパイル使用メモリ 10,496 KB
実行使用メモリ 7,884 KB
最終ジャッジ日時 2023-08-16 11:04:44
合計ジャッジ時間 1,489 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,716 KB
testcase_01 AC 15 ms
7,864 KB
testcase_02 AC 17 ms
7,824 KB
testcase_03 AC 19 ms
7,792 KB
testcase_04 AC 19 ms
7,780 KB
testcase_05 AC 30 ms
7,820 KB
testcase_06 AC 20 ms
7,792 KB
testcase_07 AC 19 ms
7,880 KB
testcase_08 AC 19 ms
7,796 KB
testcase_09 AC 19 ms
7,872 KB
testcase_10 AC 26 ms
7,788 KB
testcase_11 AC 26 ms
7,884 KB
testcase_12 AC 26 ms
7,788 KB
testcase_13 AC 26 ms
7,816 KB
testcase_14 AC 16 ms
7,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

INF = 10**18
res = INF
n = 0

while n ** 2 <= A + B:
    n += 1
    if (A + B) % n == 0:
        if (A + n) % B == 0 and (B + n) % A == 0 and A != n and B != n:
            res = min(res, n)
        m = (A + B) // n
        if (A + m) % B == 0 and (B + m) % A == 0 and A != m and B != m: 
            res = min(res, (A + B) // n)

print(res if res != INF else -1)
0