sieve of eratosthenes 썸네일형 리스트형 Problem 10 - Calculate the sum of all the primes below two million. 링크 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. python - sieve of Eratosthenes def sieve(n): l = range(n+1) l[1] = 0 sqn = int(round(n**0.5)) for i in range(2, sqn + 1): if l[i] == i: l[2*i:n+1:i] = [i] * (n/i-1) return l n = 2000000 sum = 0 siv = sieve(n) for i in range(n): if siv[i] == i: sum += i print sum 더보기 이전 1 다음