[ create a new paste ] login | about

Link: http://codepad.org/AWFZdG1J    [ raw code | fork ]

Python, pasted on Aug 11:
# n以下の素数リスト
# エラトステネスのふるい
# 参考:http://qiita.com/neko_the_shadow/items/4ebad619564a48f5a97f
def primes(n):
    plist = [i for i in range(n + 1)]
    plist[0] = 0
    plist[1] = 0

    for p in plist:
        if p == 0:
            continue
        if p * p > n:
            return [p for p in plist if p != 0]

        for a in range(2 * p, n + 1, p):
            plist[a] = 0

N = 1000000
plist = primes(N)
n = plist[0]
for p in plist[1:]:
    if n * p > N:
        print(n)
        break
    n = n * p


Create a new paste based on this one


Comments: