UVa 10087

From Algorithmist
Jump to navigation Jump to search

10087 - The Tajmahal of ++Y2k[edit]

Summary[edit]

Find magic squares with given magic constants.

Explanation[edit]

It is very hard to write a program to construct ALL magic squares, but since this problem only asks you to find ONE magic square, this is easy. Such methods are well-known. Check out these pages:

http://en.wikipedia.org/wiki/Magic_square

http://mathworld.wolfram.com/MagicSquare.html

Gotcha's[edit]

1. There are NO 2x2 magic squares. Beware!

2. You can have 0 or negative integers in your generated squares.

Input[edit]

3 15
3 10
3 9

Output[edit]

         8          1          6
         3          5          7
         4          9          2

You can't be like Shahjahan!

         6         -1          4
         1          3          5
         2          7          0