Constructing magic squares: an integer constraint satisfaction problem and a fast approach
João Vitor Pamplona, Maria Eduarda Pinheiro, Luiz-Rafael Santos
Source record
Source: Crossref
Published: Mar 31, 2026
DOI: 10.1007/s40314-026-03731-3
Open original source ↗Source abstract
Abstract Magic squares are a fascinating mathematical challenge that has intrigued mathematicians for centuries. Given a positive (and possibly large) integer n , one of the main challenges that still remains is to find, within a reasonable computational time, a magic square of order n , that is, a square matrix of order n with unique integers from a min to a max , such that the sum of each row, column, and diagonal equals a constant C ( A ) . In this work, we first present an integer constraint satisfaction problem for constructing a magic square of order n . Nonetheless, the solution time of this problem grows exponentially as the order increases. To overcome this limitation, we also propose a fast approach that constructs magic squares depending on whether n is odd, singly even, or doubly even. Moreover, we provide a proof of the correctness of this novel approach. Our numerical results show that our method can construct magic squares of order up to 70 000 in less than 140 seconds, demonstrating its efficiency and scalability.
Evidence graph
No public relationships recorded yet.
Integrity note: This page is a factual metadata record created by deterministic ingestion. It is not a claim that the work moves a mathematical frontier or has been independently verified.