結果

問題 No.36 素数が嫌い!
ユーザー rpy3cpprpy3cpp
提出日時 2015-08-04 00:52:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,158 ms / 5,000 ms
コード長 685 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 10,872 KB
実行使用メモリ 8,736 KB
最終ジャッジ日時 2023-09-09 07:14:41
合計ジャッジ時間 6,541 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 286 ms
8,568 KB
testcase_01 AC 40 ms
8,736 KB
testcase_02 AC 19 ms
8,720 KB
testcase_03 AC 19 ms
8,552 KB
testcase_04 AC 19 ms
8,580 KB
testcase_05 AC 22 ms
8,504 KB
testcase_06 AC 23 ms
8,700 KB
testcase_07 AC 23 ms
8,660 KB
testcase_08 AC 19 ms
8,720 KB
testcase_09 AC 19 ms
8,528 KB
testcase_10 AC 19 ms
8,692 KB
testcase_11 AC 389 ms
8,688 KB
testcase_12 AC 1,158 ms
8,528 KB
testcase_13 AC 1,146 ms
8,556 KB
testcase_14 AC 27 ms
8,716 KB
testcase_15 AC 19 ms
8,720 KB
testcase_16 AC 19 ms
8,580 KB
testcase_17 AC 20 ms
8,684 KB
testcase_18 AC 19 ms
8,688 KB
testcase_19 AC 66 ms
8,572 KB
testcase_20 AC 57 ms
8,572 KB
testcase_21 AC 169 ms
8,576 KB
testcase_22 AC 37 ms
8,664 KB
testcase_23 AC 27 ms
8,580 KB
testcase_24 AC 183 ms
8,664 KB
testcase_25 AC 217 ms
8,684 KB
testcase_26 AC 418 ms
8,684 KB
testcase_27 AC 40 ms
8,504 KB
testcase_28 AC 410 ms
8,504 KB
testcase_29 AC 30 ms
8,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import collections

def factorize(n):
    ''' returns a list of prime factors of n.
    ex. factorize(24) = [2, 2, 2, 3]
    source: Rossetta code: prime factorization (slightly modified)
    http://rosettacode.org/wiki/Prime_decomposition#Python:_Using_floating_point
    '''
    step = lambda x: 1 + (x<<2) - ((x>>1)<<1)
    maxq = int(math.floor(math.sqrt(n)))
    d = 1
    q = n % 2 == 0 and 2 or 3
    while q <= maxq and n % q != 0:
        q = step(d)
        d += 1
    return q <= maxq and [q] + factorize(n//q) or [n]

N = int(input())
factors = factorize(N)
freqs = collections.Counter(factors)
if sum(freqs.values()) > 2:
    print('YES')
else:
    print('NO')
0