에라토스테네스의 체: 두 판 사이의 차이
내용 삭제됨 내용 추가됨
101번째 줄:
◆ python(3.6.4)으로 구현<ref>{{웹 인용|url=http://code.jasonbhill.com/sage/project-euler-problem-10/|제목=Project Euler Problem 10 {{!}} Jason's Code Blog|언어=en-US|확인날짜=2018-03-13}}</ref>
<source lang="python3">
def prime_sum(n):
primes = [True] * n
primes[0], primes[1] = [None] * 2
sum = 0
for ind, val in enumerate(primes):
if val is True and ind > n ** 0.5 + 1:
sum += ind
elif val is True:
primes[ind * 2::ind] = [False] * (((n - 1) // ind) - 1)
print(sum)
</source>
|