
Ubiquity Technology The spring recruitment written exams have begun, and Ubiquity, a well-known foreign company, has started the 180-minute written exam mode of hell. Let's take a look at one of them with this algorithmic question on Rubik's Cube.
It is known that an odd-ordered magic square matrix is a two-dimensional matrix such that it has an equal number of odd N of rows and columns, and that the sums of each row, column, and diagonal are equal when 1 to N^2 consecutive integers are filled into the N^2 lattice. The following general solution exists for any odd-ordered magic square matrix:
An odd-ordered magic square matrix Array[N][N], (subscripts from 0 to N-1)
- The middle column of row 0 is filled with integer 1, i.e., Array[0][(N - 1) / 2] = 1;
- If the current position of the filled number is the last column of row 0 (Array[0][N-1] in the upper right corner of the matrix), the next filled position is the number of rows plus one, with the columns remaining the same (Array[1][N-1]);
- If the current filled row is row 0 but not the last column, then the next number filled row is the last row and column is the next column of the column the current number is in (Array[N-1][col+1]);
- If the current filled row is not row 0, but it is already the last column, then the next number filled row is the 0th column of the previous row of the current number (Array[row-1][0]);
- If conditions 1, 2, 3 and 4 are not met, the next number of rows to be filled in is the previous row of the current row, and the number of columns is the next column of the current column; (the number of rows decreases, and if it decreases to the 0th row, then it goes back to the last row; the number of columns increases, and if it increases to the last column, then it goes back to the 0th column)
- If the conditions 1, 2, 3, 4 are not met but the position calculated in accordance with condition 5 has been filled in the number, then the next position filled in the current position of the number of rows plus one, the columns remain unchanged (Array[row+1][col]);
- Fill in these integers from 1 to N^2 in order according to the rule of 1 to 6, and what you end up with is a generalized solution to a magic square matrix of odd order.
For example, the sum of each row, column, and each diagonal number of a 3-order Rubik's Cube matrix is 15;

The sum of each row, column, and diagonal number of a 5-order Rubik's Cube matrix is 65;

Please implement the corresponding code according to the generic solution description of the odd-ordered Rubik's cube matrix above. Require that the input argument to the program be a positive integer odd number (9, 11, 15, etc.) and the output be a row-order traversal output of the matrix (a separate row for each array element).
(Note: There are multiple solutions to the Rubik's cube matrix, and there are differences in the arrangement of matrix elements in different solutions, so please realize it strictly according to the rules)
Let's take a look at the ideas
An odd-ordered Rubik's cube matrix is a square matrix in which the numbers in each row, column, and both diagonals add up to the same number. For N A Rubik's cube matrix of order (where N is the number of cells on the side length and N is odd), the matrix can be populated by the following steps:

We offer OA ghostwriting services, please note that if you are searching for this article during the OA process, then unfortunately we will not be able to serve you. Thanks to our excellent service and competitive prices, our OA ghostwriting service has to be booked in order to be implemented. Our OA ghostwriting is a fee-based service, so those who are looking for answers for free should notContact Us.
We provide OA agency services. Please note that if you search for this article during the OA process, unfortunately, we will not be able to serve you. to our high-quality service and competitive pricing, our OA outsourcing service requires an appointment to be implemented. Our OA agency is a paid service. If you want to get answers for free, please do not contact us.