'''
每层需要覆盖的方块数:
Layers(x,y,z,n) = 2*(x*y+y*z+x*z)+4*(x+y+z+n-2)*(n-1)
'''
from itertools import count
from numba import jit
from functools import lru_cache
@lru_cache(maxsize=None)
@jit
def nCubics(x,y,z,n):
return 2*(x*y+y*z+x*z)+4*(x+y+z+n-2)*(n-1)
def getMinNumberOfCuboids(C, maxN=20000):
dCuboids = {}
for w in count(1):
num = nCubics(w, w, w, 1)
if num > maxN: break
for h in count(w):
num = nCubics(w, h, h, 1)
if num > maxN: break
for d in count(h):
num = nCubics(w, h, d, 1)
if num > maxN: break
for l in count(2):
dCuboids[num] = dCuboids.get(num, 0) + 1
num = nCubics(w, h, d, l)
if num > maxN: break
return min([key for key, value in dCuboids.items() if value == C])
print(getMinNumberOfCuboids(1000))
18522
[Finished in 16.3s] |