結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 16 ms
7,984 KB
testcase_02 AC 16 ms
8,036 KB
testcase_03 WA -
testcase_04 AC 17 ms
8,112 KB
testcase_05 AC 20 ms
7,956 KB
testcase_06 AC 17 ms
7,972 KB
testcase_07 AC 16 ms
7,952 KB
testcase_08 AC 16 ms
7,972 KB
testcase_09 AC 16 ms
8,028 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 18 ms
8,100 KB
testcase_13 AC 18 ms
7,944 KB
testcase_14 AC 15 ms
8,148 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 not (A_rest + divisor % B) % B and not (B_rest + divisor % A) % A:
            print(divisor)
            return
    print(-1)


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