結果

問題 No.36 素数が嫌い!
ユーザー n_knuun_knuu
提出日時 2015-05-23 00:54:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 274 ms / 5,000 ms
コード長 1,543 bytes
コンパイル時間 435 ms
コンパイル使用メモリ 87,244 KB
実行使用メモリ 77,944 KB
最終ジャッジ日時 2023-09-09 07:09:59
合計ジャッジ時間 7,347 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 194 ms
77,420 KB
testcase_01 AC 237 ms
77,572 KB
testcase_02 AC 126 ms
76,948 KB
testcase_03 AC 127 ms
77,124 KB
testcase_04 AC 130 ms
77,096 KB
testcase_05 AC 131 ms
77,748 KB
testcase_06 AC 130 ms
77,616 KB
testcase_07 AC 132 ms
77,516 KB
testcase_08 AC 129 ms
77,860 KB
testcase_09 AC 132 ms
77,452 KB
testcase_10 AC 130 ms
77,456 KB
testcase_11 AC 177 ms
77,700 KB
testcase_12 AC 273 ms
77,744 KB
testcase_13 AC 274 ms
77,692 KB
testcase_14 AC 219 ms
77,516 KB
testcase_15 AC 128 ms
77,116 KB
testcase_16 AC 129 ms
77,080 KB
testcase_17 AC 129 ms
76,816 KB
testcase_18 AC 128 ms
77,456 KB
testcase_19 AC 184 ms
77,496 KB
testcase_20 AC 273 ms
77,448 KB
testcase_21 AC 238 ms
77,700 KB
testcase_22 AC 243 ms
77,448 KB
testcase_23 AC 199 ms
77,692 KB
testcase_24 AC 211 ms
77,736 KB
testcase_25 AC 207 ms
77,740 KB
testcase_26 AC 217 ms
77,692 KB
testcase_27 AC 254 ms
77,524 KB
testcase_28 AC 216 ms
77,944 KB
testcase_29 AC 269 ms
77,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# used in ProjectEuler No.12, yukicoder No.36

from copy import deepcopy
from functools import reduce

class Divisor:
    def __init__(self, n):
        """ make divisors list and prime factorization list of n"""
        number = n
        if number == 1:
            self.primeFactorization = {1: 1}
        else:
            self.primeFactorization = {}
            for i in range(2, int(n**0.5)+1):
                cnt = 0
                while number % i == 0:
                    cnt += 1;
                    number //= i
                if cnt > 0:
                    self.primeFactorization[i] = cnt
            if number > 1:
                self.primeFactorization[n] = 1

    def primeFactors(self):
        return deepcopy(self.primeFactorization)

    def numDivisors(self):
        """ the number of divisors """
        if self.primeFactorization.get(1, 0) == 1:
            return 1
        numDiv = 1
        for _, cnt in self.primeFactorization.items():
            numDiv *= cnt+1
        return numDiv

    def sumDivisors(self):
        return reduce(lambda x, y: x * y, [sum(p**i for i in range(n+1)) for p, n in self.primeFactorization.items()])

N = int(input())
d = Divisor(N)
ps = d.primeFactors()
if len(ps) > 2:
    print('YES')
elif len(ps) == 2:
    for d, cnt in ps.items():
        if cnt > 1:
            print('YES')
            break
    else:
        print('NO')
elif len(ps) == 1:
    for d, cnt in ps.items():
        if cnt > 2:
            print('YES')
            break
    else:
        print('NO')
0