Magic Square
Time limit2sMemory limit128 MB
Construct and print any N by N magic square for a given N between 3 and 300 using integers 1 through N^2.
- Level
Medium7 of 10
- Topics
- Math, Matrix, Implementation, Simulation
- Solved
- No attempts yet
Problem
A magic square is an arrangement of the integers from 1 through N^2 in an N by N grid, using each integer exactly once, such that every row, every column, and the two main diagonals all have the same sum.
Given N, print any N by N magic square.
Input
The first line contains a natural number N. (3 <= N <= 300)
Output
Print any N by N magic square that satisfies the condition. Print N integers on each line, separated by spaces.