#C7777. Spiral Number Matrix

    ID: 51685 Type: Default 1000ms 256MiB

Spiral Number Matrix

Spiral Number Matrix

You are given an integer ( n ) such that ( 1 \le n \le 20 ). Your task is to generate an ( n \times n ) matrix filled with the numbers from 1 to ( n^2 ) in spiral order starting from the top-left corner and moving to the right initially. The spiral continues in the clockwise direction until the entire matrix is filled.

For example, when ( n = 3 ), the matrix should be:

1 2 3
8 9 4
7 6 5

Print the resulting matrix to stdout where each row is on a new line and each number in the row is separated by a space.

inputFormat

The input consists of a single integer ( n ) read from standard input.

outputFormat

Output the ( n \times n ) spiral matrix. Each of the ( n ) lines should contain ( n ) integers separated by a space.## sample

1
1

</p>