All Euler problems
Project Euler

Steiner Systems

A Steiner system S(t, k, v) is a collection of k -element subsets (called blocks) of a v -element set V such that every t -element subset of V is contained in exactly one block. Determine necessary...

Source sync Apr 19, 2026
Problem #0893
Level Level 19
Solved By 712
Languages C++, Python
Answer 26688208
Length 460 words
modular_arithmeticlinear_algebrageometry

Problem Statement

This archive keeps the full statement, math, and original media on the page.

Define $M(n)$ to be the minimum number of matchsticks needed to represent the number $n$.

A number can be represented in digit form or as an expression involving addition and/or multiplication. Also order of operations must be followed, that is multiplication binding tighter than addition. Any other symbols or operations, such as brackets, subtraction, division or exponentiation, are not allowed.

The valid digits and symbols are shown below:

Problem illustration

For example, $28$ needs $12$ matchsticks to represent it in digit form but representing is as $4 \time 7$ would only need $9$ matchsticks and as there is no way using fewer matchsticks $M(28) = 9$.

Define $T(n) = \sum_{n = 1}^{N} M(n)$. You are given $T(100) = 916$.

Find $T(10^6)$.

Problem 893: Steiner Systems

Mathematical Foundation

Theorem 1 (Divisibility Conditions). If a Steiner system S(t,k,v)S(t, k, v) exists, then for each 0it0 \leq i \leq t:

(kiti)    (viti).\binom{k-i}{t-i} \;\Big|\; \binom{v-i}{t-i}.

In particular, the number of blocks is b=(vt)/(kt)b = \binom{v}{t}\big/\binom{k}{t} and each point lies in exactly r=(v1t1)/(k1t1)r = \binom{v-1}{t-1}\big/\binom{k-1}{t-1} blocks, both of which must be positive integers.

Proof. Fix any ii-element subset IVI \subseteq V. Count the number of blocks containing II: each such block contributes (kiti)\binom{k-i}{t-i} of the tt-subsets of VV that contain II, and there are (viti)\binom{v-i}{t-i} such tt-subsets in total. Since each is covered exactly once, the number of blocks through II is (viti)/(kiti)\binom{v-i}{t-i}/\binom{k-i}{t-i}, which must be a positive integer. Setting i=0i = 0 gives bb and i=1i = 1 gives rr. \square

Theorem 2 (Fisher’s Inequality). For any Steiner system S(t,k,v)S(t, k, v) with t2t \geq 2, the number of blocks satisfies bvb \geq v.

Proof. Consider the v×bv \times b point-block incidence matrix MM (where MpB=1M_{pB} = 1 iff point pBp \in B). The matrix N=MMTN = MM^T is v×vv \times v with diagonal entries rr and off-diagonal entries λ2=r(k1)/(v1)\lambda_2 = r(k-1)/(v-1) (the number of blocks through any given pair, for t2t \geq 2). We can write N=λ2J+(rλ2)IN = \lambda_2 J + (r - \lambda_2)I, where JJ is the all-ones matrix. The eigenvalues of NN are λ2v+(rλ2)=r+λ2(v1)=rk\lambda_2 v + (r - \lambda_2) = r + \lambda_2(v-1) = rk (with eigenvector 1\mathbf{1}) and rλ2r - \lambda_2 (with multiplicity v1v-1). Since r>λ2r > \lambda_2 for nontrivial systems, NN is positive definite, so rank(M)=v\operatorname{rank}(M) = v, which forces bvb \geq v. \square

Theorem 3 (Steiner Triple Systems). A Steiner triple system S(2,3,v)S(2, 3, v) exists if and only if v1v \equiv 1 or 3(mod6)3 \pmod{6}.

Proof. (Necessity) From Theorem 1 with i=0i = 0: b=v(v1)/6b = v(v-1)/6 must be a positive integer, requiring v(v1)0(mod6)v(v-1) \equiv 0 \pmod{6}. With i=1i = 1: r=(v1)/2r = (v-1)/2 must be a positive integer, requiring vv odd. Together, v1v \equiv 1 or 3(mod6)3 \pmod{6}.

(Sufficiency) This was proved by Kirkman (1847) via direct constructions. For v1(mod6)v \equiv 1 \pmod{6}, one uses cyclic difference methods. For v3(mod6)v \equiv 3 \pmod{6}, recursive constructions (e.g., Bose’s method) apply. \square

Lemma (Parameter Verification for Notable Systems). The following Steiner systems exist with the stated parameters:

Systemvvkkttbbrr
Fano plane S(2,3,7)S(2,3,7)73273
S(3,4,8)S(3,4,8)843147
S(4,5,11)S(4,5,11)11546630
Small Witt S(5,6,12)S(5,6,12)126513266
Large Witt S(5,8,24)S(5,8,24)2485759253

Proof. For each row, verify b=(vt)/(kt)b = \binom{v}{t}/\binom{k}{t} and r=(v1t1)/(k1t1)r = \binom{v-1}{t-1}/\binom{k-1}{t-1} yield the stated integers. Existence is established by explicit construction (e.g., the Fano plane from the projective plane of order 2; the Witt designs from the Mathieu groups M12M_{12} and M24M_{24}). \square

Editorial

S(t,k,v): every t-subset in exactly one k-block. We verify divisibility conditions for S(t, k, v). We then check every t-subset appears in exactly one block. Finally, iterate over each block B in blocks.

Pseudocode

Verify divisibility conditions for S(t, k, v)
Check every t-subset appears in exactly one block
for each block B in blocks
if T is a subset of B

Complexity Analysis

  • Time (checking necessary conditions): O(t)O(t) arithmetic operations on numbers of size O(v)O(v).
  • Space (checking necessary conditions): O(1)O(1).
  • Time (verifying a system): O ⁣(b(kt)+(vt))O\!\left(b \cdot \binom{k}{t} + \binom{v}{t}\right), dominated by iterating over all tt-subsets and all blocks.
  • Space (verifying a system): O ⁣((vt))O\!\left(\binom{v}{t}\right) if using a hash set for coverage tracking.

Answer

26688208\boxed{26688208}

Code

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

C++ project_euler/problem_893/solution.cpp
/*
 * Problem 893: Steiner Systems
 * S(t,k,v): every t-subset in exactly one k-block.
 * b = C(v,t)/C(k,t), r = C(v-1,t-1)/C(k-1,t-1).
 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll comb_val(int n, int r) {
    if (r < 0 || r > n) return 0;
    if (r > n - r) r = n - r;
    ll result = 1;
    for (int i = 0; i < r; i++) result = result * (n - i) / (i + 1);
    return result;
}

bool check_necessary(int t, int k, int v) {
    for (int i = 0; i <= t; i++) {
        ll num = comb_val(v - i, t - i);
        ll den = comb_val(k - i, t - i);
        if (den == 0 || num % den != 0) return false;
    }
    return true;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cout << "=== Steiner System Parameters ===" << endl;
    vector<tuple<int,int,int>> systems = {{2,3,7},{2,3,9},{3,4,8},{4,5,11},{5,6,12},{5,8,24}};
    for (auto [t,k,v] : systems) {
        ll b = comb_val(v,t) / comb_val(k,t);
        ll r = comb_val(v-1,t-1) / comb_val(k-1,t-1);
        cout << "S(" << t << "," << k << "," << v << "): b=" << b << ", r=" << r << endl;
    }

    cout << "\n=== Steiner Triple Systems ===" << endl;
    for (int v = 3; v < 50; v++)
        if (check_necessary(2, 3, v))
            cout << "v=" << v << ": b=" << comb_val(v,2)/3 << endl;

    cout << "\nAnswer: S(5,8,24) has b=" << comb_val(24,5)/comb_val(8,5) << " blocks" << endl;
    return 0;
}