[문제]
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))
'''
완전 비효율적인 코드인 걸 안다...
며칠을 고민을 해봐도 답이 영 안나온다.
구글링을 해본 결과 에라토스테네스의 체 방식을 이용해서 푸는 것이 일반적인 풀이 방식이라고 한다.
구글링을 하면서 본 코드들이 자꾸 머리속에 떠다녀서
나중에 다시 풀어보기로 했다..
'''
'파이썬' 카테고리의 다른 글
[Project Euler]12. Highly divisible triangular number (0) | 2021.06.06 |
---|---|
[Project Euler]11. Largest product in a grid (0) | 2021.06.02 |
[Project Euler]9. Special Pythagorean triplet (0) | 2021.05.29 |
[Project Euler]8. Largest product in a series (0) | 2021.05.28 |
[Project Euler]7. 10001st prime (0) | 2021.05.27 |