Advertisement
banovski

Project Euler, Problem #10, Python

Feb 9th, 2022
1,097
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. #! /usr/bin/env python3
  2.  
  3. # The task: the sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find
  4. # the sum of all the primes below two million.
  5.  
  6. s = set()
  7. r = 2
  8.  
  9. for m in range(2, 1000001):
  10.     for u in range(2 * m, 2000001, m):
  11.         s.add(u)
  12.  
  13. for i in range(3, 2000001, 2):
  14.     if not i in s:
  15.         r += i
  16.  
  17. print(r)
  18.  
  19. # 142913828922
  20. # 25326301 function calls in 19.818 seconds
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement