-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem47.py
More file actions
50 lines (42 loc) · 1.17 KB
/
problem47.py
File metadata and controls
50 lines (42 loc) · 1.17 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
49
"""
Distinct primes factors
Project Euler Problem #47
by Muaz Siddiqui
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?
"""
from euler_helpers import timeit, prime_factors
def num_distinct_primes(n):
primefac = prime_factors(n)
count = 0
while len(primefac) > 0:
count += 1
primefac = [value for value in primefac if value != primefac[0]]
return count
@timeit
def answer():
first = 648
found = False
while not found:
if num_distinct_primes(first) != 4:
first += 1
continue
elif num_distinct_primes(first + 1) != 4:
first += 2
continue
elif num_distinct_primes(first + 2) != 4:
first += 3
continue
elif num_distinct_primes(first + 3) != 4:
first += 4
continue
else:
found = True
return first