-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathproblem47.py
More file actions
56 lines (50 loc) · 1.1 KB
/
problem47.py
File metadata and controls
56 lines (50 loc) · 1.1 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
50
51
52
53
54
55
56
import math
def is_prime(n):
if n < 2:
return False
for j in range(2, math.sqrt(n) + 1):
if n%j == 0:
return False
return True
def get_factors(n):
factors = []
for j in range(2, math.sqrt(n) + 1):
if n%j == 0:
factors.append(j)
factors.append(n/j)
return factors
def get_prime_factors(n):
pf = []
seq = []
factors = get_factors(n)
for factor in factors:
if is_prime(factor):
pf.append(factor)
while len(pf):
prime = pf.pop()
n /= prime
seq.append(prime)
if n > 0:
if n in seq:
seq[seq.index(n)] *= 2
return seq
consecutive = 0
i = 647
found = []
while consecutive < 4:
i += 1
factors = get_prime_factors(i)
if len(factors) == 4:
unique = True
for factor in factors:
if factor in found:
consecutive = 0
unique = False
found = []
break
else:
unique = False
if unique:
found += factors
consecutive += 1
print i