2188.Magic Odd Square

Time Limit: 1s Memory Limit: 256MB

Find an n \times n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd.

Input Format(From the terminal/stdin)

The only line contains odd integer n (1 \le n \le 49).

Output Format(To the terminal/stdout)

Print n lines with n integers. All the integers should be different and from 1 to n2. The sum in each row, column and both main diagonals should be odd.

Sample Input 1

Copy
1
 \n

Sample Output 1

Copy
1
 \n

Sample Input 2

Copy
3
 \n

Sample Output 2

Copy
2 1 4
3 5 7
6 9 8
 · · \n
 · · \n
 · · \n

Submit

请先 登录

© 2025 FAQs