結果

問題 No.1063 ルートの計算 / Sqrt Calculation
ユーザー ThetaTheta
提出日時 2022-10-21 13:15:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 931 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 8,284 KB
最終ジャッジ日時 2023-09-13 14:52:05
合計ジャッジ時間 1,560 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,140 KB
testcase_01 AC 18 ms
8,216 KB
testcase_02 AC 17 ms
8,220 KB
testcase_03 AC 17 ms
8,116 KB
testcase_04 AC 17 ms
8,284 KB
testcase_05 AC 16 ms
8,216 KB
testcase_06 AC 16 ms
8,148 KB
testcase_07 AC 18 ms
8,200 KB
testcase_08 AC 17 ms
8,140 KB
testcase_09 AC 18 ms
8,284 KB
testcase_10 AC 17 ms
8,196 KB
testcase_11 AC 16 ms
8,272 KB
testcase_12 AC 17 ms
8,148 KB
testcase_13 AC 17 ms
8,216 KB
testcase_14 AC 16 ms
8,136 KB
testcase_15 AC 17 ms
8,144 KB
testcase_16 AC 17 ms
8,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import count


def calc_positive_divisors(num: int) -> dict[int, int]:
    if num < 2:
        raise ValueError

    divisors = {}
    for divisor in count(2):
        if divisor ** 2 > num:
            if num != 1:
                divisors[num] = 1
            break
        while num % divisor == 0 and num != 1:
            try:
                divisors[divisor] += 1
            except KeyError:
                divisors[divisor] = 1
            num //= divisor

    return divisors


def main():
    N = int(input())
    match N:
        case 1:
            print(1, 1)
        case 2:
            print(1, 2)
        case num:
            a, b = 1, 1
            divisors = calc_positive_divisors(num)
            for divisor, count_ in divisors.items():
                a *= divisor ** (count_ // 2)
                b *= divisor ** (count_ % 2)
            print(a, b)


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