-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path047.py
More file actions
48 lines (34 loc) · 1.16 KB
/
047.py
File metadata and controls
48 lines (34 loc) · 1.16 KB
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
43
44
45
46
47
48
"""
Problem 47
==========
The first two consecutive numbers to have two distinct prime factors are:
14 = 2 × 7
15 = 3 × 5
The first three consecutive numbers to have three distinct prime factors
are:
644 = 2² × 7 × 23
645 = 3 × 5 × 43
646 = 2 × 17 × 19.
Find the first four consecutive integers to have four distinct prime
factors. What is the first of these numbers?
Answer: 748f517ecdc29106e2738f88aa7530f4
"""
from common import check, is_prime, get_factors
from itertools import count
PROBLEM_NUMBER = 47
ANSWER_HASH = "748f517ecdc29106e2738f88aa7530f4"
def get_prime_factors(n):
return [f for f in get_factors(n) if is_prime(f) and f != 1 and f != n]
def find(number):
factors = [None] * number
for i in count(1):
for l, d in enumerate(reversed(factors)):
if l == 0:
continue
factors[number-l] = d
factors[0] = get_prime_factors(i)
if i < number or any(len(f) != number for f in factors):
continue
return i-number+1
result = find(4)
check(result, PROBLEM_NUMBER, ANSWER_HASH)