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.

In [1]:
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$.

In [2]:
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.

In [3]:
from itertools import count

total = 0
for M in count(1):
    total += count_cuboids(M)
    if total > 1000000:
        break
        
M
Out[3]:
1818

Relevant sequences¶

  • Number of pairs $a,b$ such that $(a+b)^2 + n^2$ is square: A143714
  • Partial sums of A143714: A143715

Copyright (C) 2025 filifa¶

This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license and the BSD Zero Clause license.