All Euler problems
Project Euler

Counting the Number of "Hollow" Square Laminae That Can Form One, Two, Three, ... Distinct Arrangements

Define N(t) as the number of hollow square laminae that can be formed using exactly t tiles. How many values of t <= 10^6 satisfy 1 <= N(t) <= 10?

Source sync May 21, 2026
Problem #0174
Level Level 05
Solved By 6,728
Languages C++, Python
Answer 209566
Length 259 words
number_theorybrute_forcelinear_algebra

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.

Given eight tiles it is possible to form a lamina in only one way: \(3 \times 3\) square with a \(1 \times 1\) hole in the middle. However, using thirty-two tiles it is possible to form two distinct laminae.

PIC

If \(t\) represents the number of tiles used, we shall say that \(t = 8\) is type \(L(1)\) and \(t = 32\) is type \(L(2)\).

Let \(N(n)\) be the number of \(t \le 1000000\) such that \(t\) is type \(L(n)\); for example, \(N(15) = 832\).

What is \(\sum \limits _{n = 1}^{10} N(n)\)?

Problem 174: Counting the Number of “Hollow” Square Laminae That Can Form One, Two, Three, … Distinct Arrangements

Mathematical Development

Theorem 1. (Tile-count parameterization.) Every hollow square lamina with outer side aa, inner side bb, a≡b(mod2)a \equiv b \pmod{2}, a≥b+2a \geq b + 2, b≥1b \geq 1, uses t=4k(b+k)t = 4k(b + k) tiles where k=(a−b)/2≥1k = (a - b)/2 \geq 1. In particular, 4∣t4 \mid t.

Proof. From Problem 173, t=a2−b2=(a−b)(a+b)t = a^2 - b^2 = (a - b)(a + b). Setting a−b=2ka - b = 2k gives a+b=2b+2ka + b = 2b + 2k, so t=2k(2b+2k)=4k(b+k)t = 2k(2b + 2k) = 4k(b + k). Since k≥1k \geq 1 and b+k≥2b + k \geq 2, we have t≥8t \geq 8 and 4∣t4 \mid t. □\square

Theorem 2. (Reduction to divisor counting.) Write t=4mt = 4m. Then N(t)N(t) equals the number of divisors kk of mm satisfying 1≤k<m1 \leq k < \sqrt{m}.

Proof. Setting q=b+kq = b + k, the equation m=k⋅qm = k \cdot q must hold with q>kq > k (since b=q−k≥1b = q - k \geq 1 requires q>kq > k). Each such factorization corresponds to a unique lamina. The number of ordered pairs (k,q)(k, q) with kq=mkq = m and k<qk < q is the number of divisors of mm strictly less than m\sqrt{m}:

N(4m)={d(m)−12if m is a perfect squared(m)2otherwiseN(4m) = \begin{cases} \frac{d(m) - 1}{2} & \text{if } m \text{ is a perfect square} \\ \frac{d(m)}{2} & \text{otherwise} \end{cases}

which in both cases equals ∣{k:k∣m,  k<m}∣|\{k : k \mid m,\; k < \sqrt{m}\}|. □\square

Lemma 1. (Divisor sieve.) For M=N/4M = N/4, the array N[1…M]N[1 \ldots M] can be computed in O(Mlog⁡M)O(M \log M) time by iterating k=1,2,…,⌊M⌋k = 1, 2, \ldots, \lfloor\sqrt{M}\rfloor and for each kk, incrementing N[kq]N[kq] for all q=k+1,k+2,…q = k + 1, k + 2, \ldots with kq≤Mkq \leq M.

Proof. Each pair (k,q)(k, q) with k<qk < q and kq=mkq = m is visited exactly once. The total number of pairs is ∑k=1⌊M⌋⌊M/k−k⌋≤∑k=1⌊M⌋M/k=O(Mlog⁡M)=O(Mlog⁡M)\sum_{k=1}^{\lfloor\sqrt{M}\rfloor} \lfloor M/k - k \rfloor \leq \sum_{k=1}^{\lfloor\sqrt{M}\rfloor} M/k = O(M \log \sqrt{M}) = O(M \log M). □\square

Editorial

The divisor reformulation turns the problem into a counting sieve on m=t/4m=t/4. For each factor pair m=kqm=kq with k<qk<q, there is exactly one hollow lamina using t=4mt=4m tiles. So instead of generating laminae geometrically, the program counts how many strict factor pairs each mm has.

The implementation loops over the smaller factor kk and increments every product kqkq with q>kq>k. After that sieve pass, the array entry for mm is exactly N(4m)N(4m). The final answer is obtained by counting how many of those entries fall between 1 and 10 inclusive.

Pseudocode

Let $M = 10^6 / 4$ and create an array of zero counts for $1 \le m \le M$.

For each possible smaller factor $k$:
    let the larger factor start at $k+1$ so that only strict pairs are counted.
    For every $q$ with $kq \le M$:
        increment the counter of $m = kq$.

After all factor pairs are processed:
    scan the array once more,
    and count how many entries lie between 1 and 10 inclusive.

Return that count.

Complexity Analysis

  • Time: O(Mlog⁡M)O(M \log M) where M=250,000M = 250{,}000. The inner loop total is bounded by ∑k=1500M/k≈Mln⁡500≈1.55×106\sum_{k=1}^{500} M/k \approx M \ln 500 \approx 1.55 \times 10^6.
  • Space: O(M)=O(250,000)O(M) = O(250{,}000) for the count array.

Answer

209566\boxed{209566}

Code

Each problem page includes the exact C++ and Python source files from the local archive.

C++ project_euler/problem_174/solution.cpp
#include <bits/stdc++.h>
using namespace std;

int main(){
    // Problem 174: Count values of t <= 10^6 with 1 <= N(t) <= 10
    // where N(t) = number of hollow square laminae with exactly t tiles.
    // t = 4*m, N(t) = number of divisors k of m with k < sqrt(m).

    const int LIMIT = 1000000;
    const int M = LIMIT / 4; // 250000

    vector<int> N(M + 1, 0);

    // For each k, count factorizations m = k * q with k < q
    for(int k = 1; (long long)k * k < M; k++){
        for(int q = k + 1; (long long)k * q <= M; q++){
            N[k * q]++;
        }
    }

    int ans = 0;
    for(int m = 1; m <= M; m++){
        if(N[m] >= 1 && N[m] <= 10) ans++;
    }

    cout << ans << endl;
    return 0;
}