結果
問題 | No.36 素数が嫌い! |
ユーザー |
|
提出日時 | 2022-11-07 14:13:27 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 1,863 ms / 5,000 ms |
コード長 | 1,116 bytes |
コンパイル時間 | 86 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-07-20 22:11:51 |
合計ジャッジ時間 | 9,352 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
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()