Cuboid Route¶
Suppose you have a cuboid with side lengths $a \leq b \leq M$. Then the shortest route will be $\sqrt{(a + b)^2 + M^2}$. We're interested in when this distance is an integer.
However, rather than iterate through values of $a$, $b$, and $M$, we can be more efficient by iterating through values of $M$, then values of $s$, where $s \leq 2M$. If $s^2 + M^2$ is a square number, then that means any $a,b$ such that $s = a+b$ and $a \leq b \leq M$ will correspond to an $a \times b \times M$ cuboid with integer shortest route.
So, if $s = a + b$, naturally $b = s - a$, and we want to know how many values of $a$ satisfy $1 \leq a \leq s - a \leq M$. We can derive four bounds on $a$ from this.
- $1 \leq a$
- $s - M \leq a$
- $a \leq \frac{s}{2}$
- $a \leq M$
From these bounds, we can get the number of cuboids that can be constructed from an $(s, M)$ pair.
def leg_splits(s, M):
max_a = min(M, s // 2 + 1)
min_a = max(s - M, 1)
return max_a - min_a
Then we can write a function to find the number of cuboids with at least one edge equaling $M$.
def count_cuboids(M):
return sum(leg_splits(s, M) for s in range(1, 2 * M + 1) if is_square(s^2 + M^2))
To get our answer, we just compute a running total and stop when it exceeds one million.
from itertools import count
total = 0
for M in count(1):
total += count_cuboids(M)
if total > 1000000:
break
M
1818
Relevant sequences¶
Copyright (C) 2025 filifa¶
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license and the BSD Zero Clause license.