-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path050.py
42 lines (36 loc) · 848 Bytes
/
050.py
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
#Project Euler Problem 50
# ### !!!
# Using the script meusPrimos.py
from meusPrimos import primes
Primes=primes(1000000)
SZ=len(Primes)
SumPrimes=[]
SumPrimes.append(0)
for i in range(SZ): SumPrimes.append(SumPrimes[-1]+Primes[i])
SumPrimesSet=set(SumPrimes)
maxjump=0
maxp=0
for j in range(SZ):
p=Primes[SZ-j-1] #get a big prime
for i in range(SZ):
sk=p+SumPrimes[i]
if sk in SumPrimesSet: #making this set boosts speed!!!
jump=SumPrimes.index(sk)-i
if jump>maxjump:
maxjump=jump
maxp=p
print maxp, maxjump, i
break
print maxp, maxjump
'''
just run for a few seconds
and the answer will show up:
999983 29 3669
999863 71 1623
999809 79 1470
999769 109 1083
999749 237 458
999721 495 53
998857 509 38
997651 543 3 <---
'''