A magic square is an n×n array of distinct positive integers (n > 1

advertisement
A magic square is an n×n array of distinct positive integers (n > 1) such that the
sum of the entries in each row, in each column, and along the two diagonals is
the same. For example, a 3×3 magic square with a sum of 2007 is shown below.
672 665 670
667 669 671
668 673 666
This month's problem is to find the smallest size magic square with a sum of
2008. Try to find such a square whose largest entry is as small as possible.
Solution:
I will always use ‘n’ to denote the size of the square, and ‘s’ to denote the magic sum.
There are two facts that I will use in solving this:
1) For any given magic square, you can multiply every entry by m and then add k to
every entry to get a magic square with sum m*s + n*k. This will be used below.
2) The sum or difference of two magic squares will result in a grid with all row, column,
and main diagonal sums the same. However, entries may be repeated or negative, so we
cannot be certain the result is a magic square.
It is easy to show that you cannot create a magic square of size 2. If any entry has value
x, then to get the row, column, and diagonal to sum to s, the other three entries must be sx. Thus, there must be a repeated entry.
For n=3, the ‘classic’ example is:
8 1 6
3 5 7
4 9 2
which has s=15. Since 15 is a multiple of 3, m*s + n*k will be a multiple of 3. 2008 is
not a multiple of 3.
If there were a magic square with sum 2008, then by taking the difference with the given
magic square with s=2007, we could get a grid with row sum being 1. Let the following
be a grid with row-sum equaling 1:
X Y ?
Z ? ?
? ? ?
Where X, Y, and Z are values we need to find, and ? denotes a value that can be
calculated from X, Y, and Z.
For the first row to sum correctly, we need the last entry to be 1 – X – Y. For the first
column to sum correctly, we need the bottom entry to be 1 – X – Z. This forces the
middle entry to be 2X + Y + Z – 1. Continuing, the lower-right entry becomes 2 – 3X – Y
– Z.
Now consider the last entry in the middle row.
To get the column correct, we need it to have the value 4X + 2Y + Z – 2.
To get the row correct, it must have the value 2 – 2X – Y – 2Z.
Setting these equal, we have:
4X + 2Y + Z – 2 = 2 – 2X – Y – 2Z. Simplifying gives:
6X + 3Y + 3Z = 4, or 2X + Y + Z = 4/3.
This can only be satisfied if at least one of the unknown values is not an integer. Thus, we
cannot make a grid with the sum of 1 if we even want to use integers, let alone any of the
other requirements. Thus, there is no magic square of size 3 with s=2008 (or, indeed, with
s not being a multiple of 3!)
We now try the next larger size.
For n=4, we have the following base magic square:
1 15 14 4
12 6 7 9
8 10 11 5
13 3 2 16
with s=34
Since 34 is not a multiple of 4, we can get any multiple of 2 to be the magic sum, using
appropriate values for k and m in m*s + n*k. Thus, we are assured that a magic square
with s=2008 exists. To find the best one, however, we need one more interesting fact.
The grid:
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
has a row sum of 2 (although is not a magic square). As long as we do not result in any
repeated values, however, we can add or subtract this from a magic square to get another,
with s being increased by 2. The 1s appear in the same locations as the numbers 9
through 16 in the base grid. Thus, if we add 493 to each entry in the base grid, and then
an additional 1 as the above grid indicates, we obtain:
494 509 508 497
506 499 500 503
501 504 505 498
507 496 495 510
Which is magic with s=2008, and maximum value 510.
Since the average entry has to have a value of 502, either eight entries must be larger than
502 and eight smaller than 502, or if fewer values are on either side of 502, they must be
correspondingly father from 502 to keep the correct average. Since this grid uses the first
8 numbers larger than 502, no other grid can have a smaller maximum value.
Download