Using Up to One Million Tiles How Many Different "Hollow" Square Laminae Can Be Formed?
A hollow square lamina is formed by removing a smaller concentric square hole from a larger square. Using up to N = 10^6 unit-square tiles, how many distinct hollow square laminae can be formed?
Problem Statement
This archive keeps the full statement, math, and original media on the page.
We shall define a square lamina to be a square outline with a square "hole" so that the shape possesses vertical and horizontal symmetry. For example, using exactly thirty-two square tiles we can form two different square laminae:

With one-hundred tiles, and not necessarily using all of the tiles at one time, it is possible to form forty-one different square laminae.
Using up to one million tiles how many different square laminae can be formed?
Problem 173: Using Up to One Million Tiles How Many Different “Hollow” Square Laminae Can Be Formed?
Mathematical Development
Definition 1. A hollow square lamina is parameterized by a pair of positive integers with and , where is the outer side length, is the inner side length, and the congruence condition ensures the hole is centered (uniform border width ).
Theorem 1 (Tile count). A hollow square lamina uses exactly tiles.
Proof. The lamina occupies unit cells minus the cells removed for the interior hole.
Lemma 1 (Factored form). Setting (the border width), the tile count becomes . For fixed border width , the outer side ranges over integers (so that ), subject to .
Proof. We have . With , we obtain , so . The constraint gives , i.e., .
Lemma 2 (Range of the outer side). The minimum tile count for a given outer side is achieved at (border width ), giving . Hence a necessary condition for a lamina with outer side to exist is .
Proof. The largest allowable inner side is , which minimizes . Computing: iff .
Theorem 2 (Counting formula). For each outer side with , the number of valid inner sides is
where and is the smallest positive integer satisfying and . If no such exists (i.e., ), then .
Proof. The valid values of form an arithmetic progression with common difference 2. The number of terms in such a progression with first term and last term is .
Corollary 1. The total number of laminae is .
Editorial
The code iterates by outer side length. For a fixed outer side , the admissible inner sides are exactly those of the same parity as , at most , and large enough that the lamina still uses no more than tiles. Once the smallest valid inner side is known, every larger inner side of matching parity is automatically valid up to , so the count for that outer side becomes a simple arithmetic progression length.
This is why the implementation never enumerates border widths explicitly. It scans outward side lengths until even the thinnest lamina already exceeds the tile budget, computes the minimal feasible inner side via the inequality , adjusts parity if necessary, and adds the number of valid inner choices in one shot.
Pseudocode
Set the tile limit to one million and initialize the answer to zero.
For each outer side length $a$ starting from 3:
If the thinnest possible lamina with this outer side already exceeds the limit,
stop the loop.
The largest inner side is always $a-2$.
Compute the smallest inner side that still satisfies $a^2-b^2 \le N$.
If the inequality is loose enough, start from the smallest positive value
with the same parity as $a$.
Otherwise derive the lower bound from the square-root threshold
and then adjust it to the correct parity.
If this minimum inner side does not exceed $a-2$,
add the number of matching-parity values from the minimum up to $a-2$.
Return the total.
Complexity Analysis
- Time: The outer loop runs for , giving iterations, each performing arithmetic (one integer square root and constant-many comparisons).
- Space: .
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
/*
* Problem 173: Count hollow square laminae with at most N = 10^6 tiles.
* Lamina (a, b): outer side a, inner side b, same parity, tiles = a^2 - b^2.
* For each a >= 3, count valid inner sides b.
*/
int main() {
long long N = 1000000;
long long total = 0;
for (long long a = 3; 4 * (a - 1) <= N; a++) {
long long b_max = a - 2;
long long lo = a * a - N;
long long b_min;
if (lo <= 1) {
b_min = (a % 2 == 0) ? 2 : 1;
} else {
b_min = (long long)ceil(sqrt((double)lo));
while (b_min * b_min < lo) b_min++;
if (b_min % 2 != a % 2) b_min++;
}
if (b_min > b_max) continue;
total += (b_max - b_min) / 2 + 1;
}
cout << total << endl;
return 0;
}
"""
Problem 173: Hollow Square Laminae
Count distinct hollow square laminae using at most N = 10^6 tiles.
Lamina (a, b): outer side a, inner side b, same parity, tiles = a^2 - b^2.
"""
import math
def solve():
N = 1_000_000
total = 0
a = 3
while 4 * (a - 1) <= N:
b_max = a - 2
lo = a * a - N
if lo <= 1:
b_min = 2 if a % 2 == 0 else 1
else:
b_min = math.isqrt(lo - 1) + 1
while b_min * b_min < lo:
b_min += 1
if b_min % 2 != a % 2:
b_min += 1
if b_min <= b_max:
total += (b_max - b_min) // 2 + 1
a += 1
print(total)
if __name__ == "__main__":
solve()