project-euler/126_cuboid_layers.py

24 lines
485 B
Python

#!/usr/bin/env python3
def fst_layer(a, b, c):
return 2*(a*b + a*c + b*c)
def abc(n):
for a in range(1, int((n//6)**0.5)+1):
for b in range(a, int((a**2 + n//2)**0.5) - a):
for c in range(b, (n - 2*a*b) // (2*a + 2*b)):
yield a,b,c
n = 2*10**4
sieve = [0]*n
for a,b,c in abc(n):
m = 0
lyn = fst_layer(a, b, c)
while lyn < n:
sieve[lyn] += 1
lyn += 4*(2*m + a + b + c)
m += 1
print(sieve.index(1000))