-
Notifications
You must be signed in to change notification settings - Fork 0
/
euler50.py
38 lines (30 loc) · 881 Bytes
/
euler50.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
from primes import primes
prime_dict = {}
def prime_sum(primes):
length = 0
for prime in primes:
for i in range(0, primes.index(prime)):
val = 0
for j in range(i,primes.index(prime)):
val += primes[j]
#if ((str(i)+","+str(j)) in prime_dict.keys()):
#val = prime_dict[str(i)+","+str(j)]
#else:
#val += primes[j]
#prime_dict[str(i)+","+str(j)] = val
if (val == prime):
if ((j - i + 1) > length):
print val
length = j - i + 1
if (val > prime):
break
return length
if __name__ == "__main__":
prime, prime_number = primes(100)
cumulative_sum = []
temp = prime_number[0]
cumulative_sum.append(temp)
for val in prime_number[1:]:
cumulative_sum.append(val + temp)
temp = val + temp
print prime_sum(prime_number, cumulative_sum)