The famous magician david copophil liked to perform the following magic: a matrix of N rows and n columns of different pictures appeared on the big screen. We named all the pictures as follows:
Each participating audience was asked to put their fingers on the picture on the top left (that is, the picture numbered 1). The magician started: the Magician told the audience to move K times on the image (move the finger to the top, bottom, left, and right adjacent pictures, if there is a picture there), and then he (the magician) and said, "You are not here." Then ...... It's true! Your finger did not point to any deleted image (pointing to the image) and then again. He told the audience to move the image for another 2 times ...... And so on. At the end, he deleted only the last image, and then successfully smiled and announced, "I have caught you !" (Applause ).
Now, David is going to perform this magic again. Unfortunately, he has a headache over the past few days. You know how hard it is to trick him into a headache! So you have to write a program to help the Group David make magic.
[Input] The input file contains an integer N (1 <n <101 ).
Output: Your program needs to output numbers as follows:
K1 X1, 1x1, 2... X1, M1
K2 X2, 1X2, 2... X2, m2
...
Ke XE, 1 XE, 2... XE, me
Ki is the number of steps for the audience to move (n <= Ki <= 300). All Ki must be complementary and different (that is, when I <> J, meet Ki <> kJ) XI, 1 Xi, 2... XI and MI are the images that David needs to delete after the audience perform the ki Movement (the order of the numbers is arbitrary, but each image can only be listed once, and at least one image is deleted each time ).
The description of each record must be in a new line. The numbers in each row must be separated by one or more spaces. After repeating e times, only one image is not deleted.
Idea: Construction, onion-style layer-by-layer Deletion
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int n;void cal() {int cnt = 2*n+1;int cur;for (int i = 1; i <= n; i++) {printf("%d", cnt);cnt += 2;cur = i;for (int j = 1; j <= i; j++) {printf(" %d", cur);cur += n-1;}printf("\n");}int d = n*(n-1)+1;for (int i = n-1; i > 1; i--) {printf("%d", cnt);cnt += 2;cur = d+(n-i);for (int j = 1; j <= i; j++) {printf(" %d", cur);cur -= n-1;}printf("\n");}}int main() {int t;scanf("%d", &t);while (t--) {scanf("%d", &n);cal();if (t)printf("\n");}return 0;}