結果

問題 No.1063 ルートの計算 / Sqrt Calculation
コンテスト
ユーザー Theta
提出日時 2022-10-21 13:15:34
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 931 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 540 ms
コンパイル使用メモリ 20,572 KB
実行使用メモリ 15,484 KB
最終ジャッジ日時 2026-03-21 12:38:17
合計ジャッジ時間 3,102 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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