WOLFRAM|DEMONSTRATIONS PROJECT

Fermat's 4n+1 Theorem and the n Queens Problem

​
step
1
board size
5
13
17
29
37
step: {2,3}
2
2
+
2
3
=13
The goal of the
n
Queens problem is to arrange
n
Queens on an
n×n
chessboard such that no Queen attacks another. Fermat's
4n+1
theorem states that each prime of the form
4n+1
can be written as a sum of two squares. A class of solutions to the
n
Queens problem corresponds to such decompositions. For example,
13=
2
2
+
2
3
. Place a Queen in the center of a
13×13
board. Move 2 squares over, 3 squares up, and place a Queen on the resulting square. Keep moving and placing Queens on the board in this manner, identifying the top and bottom edges as well as the right and left edges of the board.