-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_50.py
More file actions
41 lines (32 loc) · 835 Bytes
/
problem_50.py
File metadata and controls
41 lines (32 loc) · 835 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
import math
import time
def is_prime(num):
if num == 2:
return True
if num == 1 or num % 2 == 0:
return False
for n in range(3,int(math.sqrt(num)+1),2):
if num % n == 0:
return False
return True
def consecutive_prime(num):
term_list = []
for n in primes_list:
term_list.append(n)
if sum(term_list) == num:
return num
if sum(term_list) > num:
break
return 0
start = time.time()
primes_list = []
for n in range(2,1000000):
if is_prime(n):
primes_list.append(n)
result = 0
for n in primes_list:
num = consecutive_prime(n)
if len(str(num)) >= len(str(result)):
result = num
print(result)
print(time.time() - start)