-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem_050.py
More file actions
31 lines (23 loc) · 766 Bytes
/
Problem_050.py
File metadata and controls
31 lines (23 loc) · 766 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
from Extra_File import get_primes_up_to
import functools
def get_sum(l):
return functools.reduce(lambda x, y: x+y, l, 0)
primes = get_primes_up_to(1000000)
primes_list = list(primes)
primes_list.sort()
longest_num = 0
longest_sum = 0
for num in reversed(primes_list):
current_start = 0
current_end = 1
current_sum = 0
while current_sum < num:
current_sum = get_sum(primes_list[current_start: current_end + 1])
current_end += 1
while current_sum > num:
current_sum = get_sum(primes_list[current_start + 1: current_end])
current_start += 1
if current_sum == num and current_end-current_start > longest_sum:
longest_sum = current_end-current_start
longest_num = num
print(longest_num)