結果

問題 No.816 Beautiful tuples
ユーザー ThetaTheta
提出日時 2022-10-25 19:34:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 19 ms / 1,500 ms
コード長 836 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 10,832 KB
実行使用メモリ 8,068 KB
最終ジャッジ日時 2023-09-16 17:09:19
合計ジャッジ時間 1,216 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,916 KB
testcase_01 AC 16 ms
7,984 KB
testcase_02 AC 17 ms
8,016 KB
testcase_03 AC 17 ms
8,020 KB
testcase_04 AC 16 ms
7,892 KB
testcase_05 AC 19 ms
7,984 KB
testcase_06 AC 17 ms
8,068 KB
testcase_07 AC 16 ms
7,912 KB
testcase_08 AC 16 ms
7,996 KB
testcase_09 AC 17 ms
7,912 KB
testcase_10 AC 18 ms
7,940 KB
testcase_11 AC 18 ms
8,024 KB
testcase_12 AC 18 ms
8,016 KB
testcase_13 AC 18 ms
7,944 KB
testcase_14 AC 16 ms
7,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt, floor


def calc_positive_divisors(num: int) -> list[int]:
    small_divisors = []
    large_divisors = []
    for n in range(1, floor(sqrt(num))+1):
        if num % n == 0:
            small_divisors.append(n)
            large_divisors.append(num//n)
    if small_divisors[-1] == large_divisors[-1]:
        large_divisors.pop()
    divisors = small_divisors + list(reversed(large_divisors))
    return divisors


def main():
    A, B = map(int, input().split())
    sum_divisors = calc_positive_divisors(A+B)
    A_rest = A % B
    B_rest = B % A
    for divisor in sum_divisors:
        if divisor in (A, B):
            continue
        if not (A_rest + divisor % B) % B and not (B_rest + divisor % A) % A:
            print(divisor)
            return
    print(-1)


if __name__ == "__main__":
    main()
0