-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem 10
More file actions
35 lines (26 loc) · 770 Bytes
/
Copy pathproblem 10
File metadata and controls
35 lines (26 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
"""
import math
import time
# this block for check numbers is it a prime or not
def checkprime(x , all_primes):
for i in range(len(all_primes)):
if x % all_primes[i] == 0 :
return False
if all_primes[i] > math.pow(x,.5):
return True
return True
# main function for send numers to an array
t0 = time.time()
upper_bound = 2000000
add = 0
all_primes=[2]
for i in range(3, upper_bound, 2):
if checkprime(i, all_primes):
all_primes.append(i)
# continuue for amin for adding all prime numbers that in array
for i in range(len(all_primes)):
add+= all_primes[i]
print(add)
print("time: ", time.time() - t0)