結果

問題 No.36 素数が嫌い!
ユーザー ThetaTheta
提出日時 2022-11-07 14:13:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,323 ms / 5,000 ms
コード長 1,116 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 8,324 KB
最終ジャッジ日時 2023-09-28 03:38:29
合計ジャッジ時間 7,195 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 328 ms
8,200 KB
testcase_01 AC 38 ms
8,192 KB
testcase_02 AC 15 ms
8,276 KB
testcase_03 AC 14 ms
8,320 KB
testcase_04 AC 14 ms
8,184 KB
testcase_05 AC 16 ms
8,116 KB
testcase_06 AC 18 ms
8,128 KB
testcase_07 AC 17 ms
8,192 KB
testcase_08 AC 14 ms
8,280 KB
testcase_09 AC 13 ms
8,180 KB
testcase_10 AC 14 ms
8,212 KB
testcase_11 AC 445 ms
8,240 KB
testcase_12 AC 1,323 ms
8,176 KB
testcase_13 AC 1,312 ms
8,184 KB
testcase_14 AC 19 ms
8,312 KB
testcase_15 AC 13 ms
8,280 KB
testcase_16 AC 14 ms
8,324 KB
testcase_17 AC 14 ms
8,324 KB
testcase_18 AC 13 ms
8,172 KB
testcase_19 AC 67 ms
8,176 KB
testcase_20 AC 56 ms
8,324 KB
testcase_21 AC 187 ms
8,280 KB
testcase_22 AC 34 ms
8,316 KB
testcase_23 AC 22 ms
8,176 KB
testcase_24 AC 202 ms
8,216 KB
testcase_25 AC 244 ms
8,188 KB
testcase_26 AC 464 ms
8,308 KB
testcase_27 AC 36 ms
8,180 KB
testcase_28 AC 450 ms
8,308 KB
testcase_29 AC 23 ms
8,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import count


def calc_prime_factorize(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())
    if N == 1:
        print("NO")
        return
    factors = calc_prime_factorize(N)

    match len(factors):
        case 0:
            raise ValueError
        case 1:
            if list(factors.values())[0] > 2:
                print("YES")
            else:
                print("NO")
        case 2:
            factors_num = set(factors.values())
            if len(factors_num) == 1 and factors_num.pop() == 1:
                print("NO")
            else:
                print("YES")

        case _:
            print("YES")


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