#K8921. Magic Square Generator
Magic Square Generator
Magic Square Generator
Given an odd integer (n) such that (3 \leq n \leq 9), generate an (n \times n) magic square using the Siamese method. A magic square is an arrangement of the numbers from 1 to (n^2) in an (n \times n) matrix, with each number occurring exactly once, such that the sum of the numbers in each row, each column, and the two main diagonals is the same. The magic constant is given by (\frac{n(n^2+1)}{2}). After generating the matrix, format the output so that each number is right-aligned in a field whose width is equal to the number of digits of (n^2). The columns should be separated by a single space, and each row should be printed on a new line.
inputFormat
The input consists of a single line containing an odd integer (n) (where (3 \leq n \leq 9)).
outputFormat
Output the correctly formatted magic square. Each row of the matrix should appear on a new line, and each number should be right-aligned in a width equal to the number of digits in (n^2), with a single space separating the numbers.## sample
3
8 1 6
3 5 7
4 9 2
</p>