2백만 까지의 소수의 합을 구하는 문제입니다.
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.
2백만까지 루프를 만들고, 소수인지를 확인해서 더해주면 됩니다.
소수확인 코드는 3번문제에서 사용했었는데, 몇가지 방법이 있는데, 적당히 선택하시면 됩니다.
1 2 3 4 5 6 7 8 9 | from sympy import isprime total = 0 i = 1 while i < 2000000 : if isprime(i): total + = i i + = 1 print (total) |