In recreational mathematics, a magic square is a square grid (where is the number of cells on each side) filled with distinct positive integers in the range such that each cell contains a different integer and the sum of the integers in each row, column and diagonal is equal. The sum is called the magic constant or magic sum of the magic square. A square grid with cells on each side is said to have order n.