fork download
  1. from math import sqrt
  2.  
  3. a=[2]
  4. y=3
  5.  
  6. def more_primes(x):
  7. for n in xrange(y, x, 2):
  8. is_prime = 1
  9. for b in a:
  10. if n%b==0:
  11. is_prime = 0
  12. break
  13. if b*b > n:
  14. break
  15. if is_prime:
  16. a.append(n)
  17. print n,
  18. print ""
  19. if x%2==0:
  20. return (x+1)
  21. else:
  22. return (x+2)
  23.  
  24. y=more_primes(40) ; print(y)
  25. y=more_primes(42) ; print(y)
  26. print(a)
  27.  
  28. y=more_primes(12) ; print(y)
  29. y=more_primes(42) ; print(y)
Success #stdin #stdout 0.01s 7728KB
stdin
Standard input is empty
stdout
3 5 7 11 13 17 19 23 29 31 37 
41
41 
43
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41]

13
13 17 19 23 29 31 37 41 
43