-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path010.py
More file actions
46 lines (34 loc) · 683 Bytes
/
010.py
File metadata and controls
46 lines (34 loc) · 683 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
36
37
38
39
40
41
42
43
44
45
46
#!python
problem = """
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
https://projecteuler.net/problem=10
"""
print(problem)
top = 2000000
primeset = [2,3]
possibles=[]
x=3
while x < top:
possibles.append(x)
x+=2
p=3
while (len(possibles)) > 0:
zoop1=len(possibles)
zoop2=len(primeset)
print("current prime:",p,",possibles:",zoop1,", primeset:",zoop2)
for x in possibles:
if ( x % p ) == 0:
possibles.remove(x)
p=possibles[0]
primeset.append(p)
del possibles[0]
if p > top**(1/2):
break
allprimes=primeset+possibles
sum=0
n=1
for p in allprimes:
sum+=p
print(n,p,sum)
n+=1