Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import sympy.ntheory as spn
- powers = {}
- powers[2] = 39
- powers[3] = 19
- powers[5] = 9
- powers[7] = 6
- powers[11] = 3
- powers[13] = 3
- powers[17] = 2
- powers[19] = 2
- powers[23] = 1
- powers[29] = 1
- powers[31] = 1
- powers[37] = 1
- powers[41] = 1
- powers[43] = 1
- limit = math.factorial(43)
- primes = sorted(list(powers.keys()))
- allProds = set()
- memo = {}
- print(limit)
- def findC(ab):
- tp = tuple()
- res = 1
- for p in primes:
- i = 1
- while ab % pow(p,i) == 0:
- i += 1
- i -= 1
- if i > powers[p]: return 0
- tp = tp + (powers[p]-i,)
- for i in range(len(primes)):
- res *= pow(primes[i], tp[i])
- return res
- def bfs(currTpls, ind, lastProd):
- if ind == len(primes): return
- print(ind, len(allProds), len(currTpls))
- newTpls = []
- p = primes[ind]
- for tp in currTpls:
- if pow(tp*lastProd,3) >= limit - int(pow(10,15)):
- for i in range(powers[p]+1):
- if pow(tp * pow(p,i)-pow(10,13),3) <= limit:
- newTpls.append(tp*pow(p, i))
- if pow(tp*pow(p,i)+pow(10,13),3) >= limit:
- allProds.add(tp*pow(p,i))
- else:
- break
- else:
- break
- newTpls = sorted(newTpls, reverse=True)
- return bfs(newTpls, ind+1, lastProd//pow(p,powers[p]))
- currTpls = []
- for i in range(powers[2]+1):
- memo[pow(2,i)] = (i)
- currTpls.append(pow(2,i))
- bfs(currTpls, 1, limit//pow(2,powers[2]))
- print(len(allProds))
- allProdsList = list(allProds)
- allProdsList.sort()
- minRatio = 10000
- minTp = []
- for i in range(len(allProdsList)):
- a = allProdsList[i]
- for j in range(i, len(allProdsList)):
- b = allProdsList[j]
- c = findC(a*b)
- if b <= c:
- if c/a < minRatio:
- minTp = [a,b,c]
- minRatio = c/a
- print(i, minRatio, minTp)
- print(minRatio)
- print(minTp)
- print(sum(minTp))
- print(limit, a*b*c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement