結果

問題 No.414 衝動
ユーザー Theta
提出日時 2022-10-24 17:29:19
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 205 ms / 1,000 ms
コード長 1,132 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-07-02 20:15:53
合計ジャッジ時間 2,339 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

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():
    M = int(input())
    if M == 1:
        print(1, 1)
        return

    if M == 2:
        print(1, 2)
        return

    divisors = calc_positive_divisors(M)
    if len(divisors) == 1 and divisors[list(divisors.keys())[0]] == 1:
        print(1, M)
    else:
        divisor = list(divisors.keys())[0]
        divisors[divisor] -= 1
        if divisors[divisor] == 0:
            divisors.pop(divisor)
        another_divisor = 1
        for divisor_, count_ in divisors.items():
            another_divisor *= divisor_ ** count_
        print(divisor, another_divisor)


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