-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.py
More file actions
26 lines (22 loc) · 800 Bytes
/
Copy pathsolution.py
File metadata and controls
26 lines (22 loc) · 800 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
import json
import time
_PRIME_FACTORS = [set(), set()]
def solution() -> int:
for n in range(2, 1000000):
limit = int(n**0.5)+1
prime_factors = set()
for i in range(2, limit+1):
if n % i == 0:
prime_factors.add(i)
prime_factors.update(_PRIME_FACTORS[n//i])
break
if not prime_factors:
prime_factors.add(n)
_PRIME_FACTORS.append(prime_factors)
if all(map(lambda x: len(x) == 4, _PRIME_FACTORS[n-3:])):
return n-3
cpu_s, wall_s = time.process_time(), time.time()
result = solution()
cpu_e, wall_e = time.process_time(), time.time()
cpu_time, wall_time = cpu_e - cpu_s, wall_e - wall_s
print(json.dumps({"solution": result, "cpu": cpu_time, "wall": wall_time}))