#K86457. Spiral Matrix Generation
Spiral Matrix Generation
Spiral Matrix Generation
Given an integer n, generate a spiral matrix of dimensions \( n \times n \) filled with consecutive numbers starting from 1 in a clockwise spiral order. If the given input is less than or equal to 0, no output should be produced.
The spiral is constructed in layers. In each layer, numbers are filled from left to right on the top row, then top to bottom on the right column, then right to left on the bottom row, and finally from bottom to top on the left column.
inputFormat
The input is read from stdin and consists of a single integer \( n \) on one line, representing the size of the matrix.
outputFormat
The output should be written to stdout and consist of the spiral matrix printed row by row. Each row is printed on a separate line with values separated by a single space. If \( n \) is less than or equal to 0, no output is produced.
## sample1
1