H-Fantastic phalanx
Time Limit: 1000 ms
Description
The magic is to place the number from 1 to N2 in a n * n matrix. Each number appears only once and
For each row, the sum of each column and its diagonal line is the same.
The focus of this problem is the odd magic square, which means that N is an odd number. You will use the following method to construct
The most basic rule of the fantasy matrix is to move to the upper right corner. Let's proceed step by step.
1. Let's start to put 1 in the middle of the top row (n = 3 in this example)
Your task is to writeProgramFind out which number will be placed in the bottom right corner of the N Magic Square, of course, you can
Use the above rule to construct the magic square.
2. Assume that the last row is the top row of the first row. Moving to the upper right corner means moving up a row and
Move one column to the right, SO 2 is placed in the last column of the last row.
3. Similarly, when the rightmost column is shifted to the right, we think that column 1st is the rightmost column. Therefore, column 3
It must be placed in the leftmost column and moved up one row.
4. What should I do if I have placed a number in the upper-right corner? When this happens, this rule
The rule of moving to the upper right corner is replaced by a direct downward placement, SO 4 will be placed
To 3.
5. Then:
1 6
3 5
4 2
6. 6 in the top right corner, 7 will normally be placed on the last line, and 6 is the rightmost, 7 should be in the normal position
Is the leftmost position. This position is in the lower left corner. This method is used to place 7. Unfortunately, 4 has been placed here,
Therefore, 7 can only be under 6.
Input
Each group has only one input n
Output
For each n, You need to output a line, indicating the number in the lower right corner of the magic. (N is an odd number smaller than 1,000,000 ),
End when the input is 0.
Sample Input
3
0
Sample output
2
Author
PCB
Haha ~ Find a regular flow ~~ But there is trick when n = 1!
# Include <iostream> using namespace STD; int main () {_ int64 N; while (CIN> N) {If (n = 0) break; if (n = 1) {cout <"1 \ n"; continue;} cout <(n-1) * (n-2)/2 + N-2) <Endl;} return 0 ;}