#K4721. Spiral Matrix Generation
Spiral Matrix Generation
Spiral Matrix Generation
Given a positive integer n which is a perfect square, generate a spiral matrix of size \(\sqrt{n} \times \sqrt{n}\). The matrix must be filled with consecutive integers starting from 1, arranged in a clockwise spiral starting from the top-left corner.
For example, when \(n = 9\), the output matrix is:
[ \begin{bmatrix} 1 & 2 & 3 \ 8 & 9 & 4 \ 7 & 6 & 5 \end{bmatrix} ]
Your task is to read the input from stdin and print the spiral matrix to stdout with each row on a new line and numbers separated by a single space.
inputFormat
The input consists of a single integer n provided in stdin. It is guaranteed that n > 0 and n is a perfect square.
Input Format:
n
outputFormat
Print the spiral matrix where each row is on a new line and each number within a row is separated by a single space. Output the result to stdout.
## sample1
1