-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprob47.py
75 lines (49 loc) · 1.16 KB
/
prob47.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import math
Primes = []
P = []
MAXN = 1000000
sqrt_MAXN = int(math.sqrt( MAXN )) + 1
def isprime( x ):
lo = 0
hi = len(Primes)-1
while lo <= hi:
mid = ( lo + hi ) / 2
if Primes[ mid ] == x:
return ( True )
elif Primes[ mid ] > x:
hi = mid-1
else:
lo = mid+1
return ( False )
for i in range( 0, MAXN ):
P.append( True )
for i in range( 2, sqrt_MAXN ):
if P[i]:
for j in range( i*i, MAXN, i ):
P[j] = False
for i in range( 2, MAXN ):
if P[i]:
Primes.append( i )
memo = {}
def distinct_fact( n ):
counter = 0
for i in Primes:
if n % i == 0:
counter += 1
if counter > 4:
return -1
while n % i == 0:
n /= i
if n == 1:
break
return ( counter )
i = 2
Found = False
while not Found:
i += 1
Found = True
for j in range( 0, 4 ):
if distinct_fact( i+j ) != 4:
Found = False
break
print "%d" % (i)