結果

問題 No.36 素数が嫌い!
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-09-25 15:20:29
言語 Python2
(2.7.18)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 1,592 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 6,668 KB
実行使用メモリ 10,504 KB
最終ジャッジ日時 2023-09-09 07:22:12
合計ジャッジ時間 2,287 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,504 KB
testcase_01 AC 28 ms
10,248 KB
testcase_02 AC 25 ms
10,340 KB
testcase_03 AC 26 ms
10,468 KB
testcase_04 AC 25 ms
10,352 KB
testcase_05 AC 26 ms
10,340 KB
testcase_06 AC 26 ms
10,312 KB
testcase_07 AC 26 ms
10,340 KB
testcase_08 AC 27 ms
10,324 KB
testcase_09 AC 26 ms
10,340 KB
testcase_10 AC 26 ms
10,252 KB
testcase_11 AC 26 ms
10,376 KB
testcase_12 AC 27 ms
10,304 KB
testcase_13 AC 30 ms
10,356 KB
testcase_14 AC 27 ms
10,316 KB
testcase_15 AC 26 ms
10,320 KB
testcase_16 AC 26 ms
10,468 KB
testcase_17 AC 27 ms
10,252 KB
testcase_18 AC 27 ms
10,384 KB
testcase_19 AC 28 ms
10,304 KB
testcase_20 AC 27 ms
10,220 KB
testcase_21 AC 26 ms
10,468 KB
testcase_22 AC 26 ms
10,440 KB
testcase_23 AC 26 ms
10,352 KB
testcase_24 AC 29 ms
10,268 KB
testcase_25 AC 26 ms
10,320 KB
testcase_26 AC 26 ms
10,464 KB
testcase_27 AC 26 ms
10,376 KB
testcase_28 AC 26 ms
10,324 KB
testcase_29 AC 27 ms
10,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
from collections import defaultdict
from fractions import gcd
from itertools import chain
from Queue import Queue
from random import randrange

flatten = chain.from_iterable

def rabin_miller(p):
    if p < 2:
        return False
    if p != 2 and p % 2 == 0:
        return False
    s = p - 1
    while s % 2 == 0:
        s >>= 1
    for _ in xrange(10):
        a = randrange(p-1) + 1
        temp = s
        mod = pow(a, temp, p)
        while temp != p-1 and mod != 1 and mod != p-1:
            mod = (mod * mod) % p
            temp *= 2
        if mod != p-1 and temp % 2 == 0:
            return False
    return True

def pollard(n):
    if n % 2 == 0:
        return 2
    x = randrange(2, 1000000)
    c = randrange(2, 1000000)
    y = x
    d = 1
    while d == 1:
        x = (x * x + c) % n
        y = (y * y + c) % n
        y = (y * y + c) % n
        d = gcd(x-y, n)
        if d == n:
            break
    return d

# Prime Factorization by Pollard Rho alrorithm
# http://code.activestate.com/recipes/577037-pollard-rho-prime-factorization/
def factorize(n):
    que = Queue()
    res = defaultdict(int)
    if n == 1:
        res[1] = 1
        return res
    que.put(n)
    while not que.empty():
        l = que.get()
        if rabin_miller(l):
            res[l] += 1
            continue
        d = pollard(l)
        que.put(d)
        if d != l:
            que.put(l / d)
    return res

n = int(raw_input())
factored = factorize(n)
arr = map(sum, zip(*factored.items()))[1:]
cnt = arr.pop() if arr else 0
print 'YES' if cnt >= 3 else 'NO'
0