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 Apr 19, 2026
Problem #0174
Level Level 05
Solved By 6,728
Languages C++, Python
Answer 209566
Length 226 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 Foundation

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

Proof. From Problem 173, t=a2b2=(ab)(a+b)t = a^2 - b^2 = (a - b)(a + b). Setting ab=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 k1k \geq 1 and b+k2b + k \geq 2, we have t8t \geq 8 and 4t4 \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 1k<m1 \leq k < \sqrt{m}.

Proof. Setting q=b+kq = b + k, the equation m=kqm = k \cdot q must hold with q>kq > k (since b=qk1b = 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:km,  k<m}|\{k : k \mid m,\; k < \sqrt{m}\}|. \square

Lemma 1. (Divisor sieve.) For M=N/4M = N/4, the array N[1M]N[1 \ldots M] can be computed in O(MlogM)O(M \log M) time by iterating k=1,2,,Mk = 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 kqMkq \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=1MM/kkk=1MM/k=O(MlogM)=O(MlogM)\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

That Can Form One, Two, Three, … Distinct Arrangements N(t) = number of laminae with exactly t tiles. Count values of t <= 10^6 with 1 <= N(t) <= 10. Key insight: t = 4m, and N(t) = number of divisors k of m with k < sqrt(m).

Pseudocode

M = N / 4 # N = 10^6, so M = 250000
count[1..M] = 0

For k from 1 to floor(sqrt(M)):
    For q from k+1 to M/k:
        m = k * q
        count[m] += 1

answer = 0
For m from 1 to M:
    If 1 <= count[m] <= 10 then
        answer += 1

Return answer

Complexity Analysis

  • Time: O(MlogM)O(M \log M) where M=250,000M = 250{,}000. The inner loop total is bounded by k=1500M/kMln5001.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;
}