-
Notifications
You must be signed in to change notification settings - Fork 0
/
_047.py
43 lines (38 loc) · 956 Bytes
/
_047.py
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
from utils import seive, is_prime
N = 10 ** 6
DISTINCT_PRIME_FACTORS = 4
primes = seive(N)
def factorize(n):
factors = set()
i = 0
prime = primes[i]
while n > 1:
if i > 100 and is_prime(n):
factors.add(n)
break
if n % prime == 0:
factors.add(prime)
n //= prime
else:
i += 1
prime = primes[i]
return list(factors)
cons, idx, len_cons = [], -1, 0
for n in range(1, N + 1):
factors = factorize(n)
if len_cons == DISTINCT_PRIME_FACTORS: break
if len(factors) == DISTINCT_PRIME_FACTORS:
if len_cons > 0:
if cons[idx] + 1 == n:
cons.append(n)
idx += 1
len_cons += 1
else:
cons = [n]
idx = 0
len_cons = 1
else:
cons = [n]
idx = 0
len_cons = 1
print(cons)