#K92372. Spiral Matrix Generation

    ID: 38183 Type: Default 1000ms 256MiB

Spiral Matrix Generation

Spiral Matrix Generation

Given two positive integers \(m\) and \(n\), generate an \(m \times n\) matrix filled with the integers from 1 to \(m\times n\) in a clockwise spiral order. The spiral begins at the top-left corner and proceeds to the right, then downwards, leftwards, and finally upwards, continuing in this manner until the entire matrix is filled.

When printing the matrix, each row should be output on a new line and the values within a row should be separated by a single space.

inputFormat

The input consists of a single line containing two space-separated integers (m) and (n), representing the number of rows and columns, respectively.

outputFormat

Output the generated spiral matrix. Print each row on a new line with the numbers separated by a single space.## sample

3 3
1 2 3

8 9 4 7 6 5

</p>