-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3smoothNumbers-462
70 lines (57 loc) · 1.61 KB
/
3smoothNumbers-462
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
#!/usr/bin/env python
"""
3-smooth numbers problem
Euler 462
Disregard, still not finished
By: A.O.
"""
import sys
import os
import string
import math
import itertools
def S(N):
sum = 0
for n in range(int(math.log(N, 2)) + 1):
sum += int(math.log(N, 3) + 1)
N >>= 1
return sum
def main(argv):
try:
print "S(N) = %d\n" % S(20)
print "S(N) = %d\n" % S(1000)
remainder, limit = 20, 20
count = 0
invalid = 0
sum = S(20)
powers2 = int(math.log(limit,2)) + 1
perms = []
for pOf2 in range(powers2):
powers3 = int(math.log(remainder,3)) + 1
print math.factorial(pOf2)*math.factorial(powers3-1)
#invalid += (powers2*powers3 - 1)
for pOf3 in range(powers3):
print "%d, %d, %d, %d, count = %d\n" % (pOf2, pOf3, 2**pOf2 * 3**pOf3, (1+pOf2)*(1+pOf3) - 1, count)
#perms.append(2**pOf2 * 3**pOf3)
invalid += math.factorial(sum-count)*((1+pOf2)*(1+pOf3) -1)*math.factorial(count)
count += 1
remainder >>= 1
#print perms
print "Invalid %d, count %d" % (invalid, count)
#print (str(math.factorial(10)-45*math.factorial(8)))
return None
for p in itertools.permutations(perms,len(perms)):
count += 1
l = list(p)
for smooth3 in l:
lowerSlice = l[:p.index(smooth3)]
#print lowerSlice
if (sum([1 for x in lowerSlice if (x % smooth3) == 0]) > 0):
#print "Bad perm: smooth3 is %d, sum is %d\n" % (smooth3, sum([x % smooth3 for x in lowerSlice]))
count -= 1
break
#print perms
except "":
return None
if __name__ == "__main__":
main(sys.argv)