You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
513 B
29 lines
513 B
9 years ago
|
import math
|
||
|
|
||
|
#find the sum of all primes under 2 million
|
||
|
#once again, it works, but it's sloooowwwww
|
||
|
|
||
|
def isPrime(number):
|
||
|
if number == 1:
|
||
|
return False
|
||
|
prime = True
|
||
|
i = 2
|
||
|
while i < math.sqrt(number) + 1:
|
||
|
if number % i == 0:
|
||
|
prime = False # found a factor, not prime
|
||
|
break
|
||
|
else:
|
||
|
i += 1
|
||
|
|
||
|
return prime
|
||
|
|
||
|
number = 3
|
||
|
sum = 2
|
||
|
|
||
|
while (number < 2000000):
|
||
|
if isPrime(number):
|
||
|
sum += number
|
||
|
number += 2
|
||
|
|
||
|
print(number)
|
||
|
print(sum)
|