-
Notifications
You must be signed in to change notification settings - Fork 0
/
047.py
61 lines (54 loc) · 1.22 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import math, time
start = time.clock()
def is_prime(n):
for i in range(2, int(math.sqrt(n))+1):
if n%i == 0:
return False
return True
def primefactors(n, lst):
if is_prime(n):
isin = False
for j in range(len(lst)):
if lst[j][0] == n:
lst[j][1] += 1
isin = True
break
if not isin:
lst.append([n,1])
return lst
for i in range(2, int(math.sqrt(n))+1):
if n%i == 0:
isin = False
for j in range(len(lst)):
if lst[j][0] == i:
lst[j][1] += 1
isin = True
break
if not isin:
lst.append([i,1])
if n/i == 1:
return lst
return primefactors(n/i, lst)
def is_disjoint(a, b):
for i in a:
if i in b:
return False
return True
def first_n(n):
for i in range(1000000):
lst = []
for j in range(n):
lst.append(primefactors(i+j, []))
if all(len(x)==n for x in lst):
disj = True
for j in range(1, n):
for k in range(j):
if not is_disjoint(lst[j], lst[k]):
disj = False
break
if disj == True:
for j in range(n):
print i+j, lst[j], len(lst[j])
return
first_n(4)
print time.clock()-start