본문 바로가기

파이썬

[Project Euler]10. Summation of primes

[문제]
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

 

[풀이]
result = list(range(3,2000000,2))


for i in result:
        result = list(filter(lambda a: not(a%i==0 and a!=i) , result))

print(sum(result))

 

'''
완전 비효율적인 코드인 걸 안다...
며칠을 고민을 해봐도 답이 영 안나온다.

구글링을 해본 결과 에라토스테네스의 체 방식을 이용해서 푸는 것이 일반적인 풀이 방식이라고 한다.

구글링을 하면서 본 코드들이 자꾸 머리속에 떠다녀서
나중에 다시 풀어보기로 했다..
'''