Try:
The mathematics — one divisibility fact decides everything
A magic rectangle wants every row to carry the same total and every column to carry the same total. Whether that is even possible comes down to a single question about whole numbers.
Average entry
A = pq + 12
Every row must sum to
q · pq + 12
Every column must sum to
p · pq + 12
The integers 1, …, pq average to A = (pq+1)/2, so a row of q entries must total qA and a column of p entries must total pA. Those totals are whole numbers only when p and q have the same parity — both odd makes pq+1 even, both even makes q/2 and p/2 whole. Mix an odd with an even and both magic constants become fractions: no magic rectangle can exist, and the nearly magic rectangle — sums differing by exactly 1 — is provably the best achievable.
The parity map — click any case to build one
q odd
q even
p odd
Magic ✓
pq + 1 is even, so both constants are whole.
try 7 × 11 →
Nearly magic ◐
Column sums equal; row sums differ by exactly 1.
try 7 × 12 →
p even
Nearly magic ◐
Column sums equal; row sums differ by exactly 1.
try 12 × 7 →
Magic ✓
p/2 and q/2 are whole, so both constants are whole.
try 8 × 10 →
2 × 2 — the lone exception.
Equal row and column sums would force two of the four entries to be equal. See for yourself →
1 × n (n > 2) — impossible.
A single line of distinct integers cannot have equal column sums. See for yourself →
Two ten-second proofs by example
| 12 | 2 | 10 | 4 | 5 | 6 | 39 |
| 1 | 11 | 3 | 9 | 8 | 7 | 39 |
| 13 | 13 | 13 | 13 | 13 | 13 |
A 2 × 6 magic rectangle. Both dimensions even: every row makes 39,
every column makes 13 — perfectly magic.
| 1 | 5 | 4 | 10 |
| 6 | 2 | 3 | 11 |
| 7 | 7 | 7 |
A 2 × 3 nearly magic rectangle. Even × odd: the columns all make 7,
and the rows land on 10 and 11 — off by exactly one, the theoretical best.
Four papers, one complete answer
- 1999Magic rectangles revisitedSettles existence once and for all (building on constructions studied since T. Harmuth in the 1880s): a p × q magic rectangle exists exactly when p and q share a parity, both exceed 1, and (p, q) ≠ (2, 2).
- 2009On a method to construct magic rectangles of even orderThe even × even recipe used here: write 1…pq in a serpentine grid, then reverse the middle rows (Case A) or perform four precise reversal-and-swap steps (Case B, both half-dimensions odd).
- 2013Construction of magic rectangles of odd orderThe odd × odd engine: a pattern matrix Gp with constant column sums is lifted to Hp, then a small set of within-column interchanges (Cases I–III of Theorem 4.1) equalises the row sums; a composition theorem handles q divisible by 3. This calculator reproduces the paper's 7 × 11 and 13 × 19 examples digit for digit.
- 2019Nearly magic rectanglesDefines the nearly magic rectangle for mixed parity and constructs one for every order where it exists: 2 × q building blocks stacked and permuted by a Kronecker-pattern matrix (p ≡ 2 mod 4), or column-block exchanges (p ≡ 0 mod 4).