Title description "What a boring world!"
Julyed felt so bored, she began to write numbers on the coordinate paper. She wrote a "0" on the center, then wrote the follow numbers clockwise, and which looked like a snake as below.
"Damn! I have fulfilled the paper! "
Julyed was looking at paper. Suddenly, she began to feel curious.
"What's the nth number on the positive axis of Y axis?"
She asked tomriddly for the question. But tomriddly is so busy that he ignored julyed. So is now there to the solve this problem.
Enter multiple test cases.
The first line contains an integer t (t <=), indicating the number of test cases.
Then T-lines follows, one line per case. Each line contains a positive integer n (n <= 3000).
Output one line per case. An integer indicates the nth number on the positive axis of Y axis. Sample input
31218
Sample output
5181314
Tips for solving problems:
Enter the 0,1,2 ... and then the number that corresponds to the output yellow mark. This problem can be answered purely by finding the law.
The pattern I found was this: 0,5,18,39, each increment of the number of add[1]=4,add[2]=13,add[3]=21, and then found that each add is increased by 8;
Here is the code.
Code:
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;intMain () {intN; intAdd=5; inta[3005]; intz=8; ints=0; intII; Memset (A,0,3005*sizeof(int)); CIN>>N; for(intI=0; i<n;i++){ for(intj=1; j<= the; j + +) {s+=add; A[J]=s; Add+=Z; } s=0; Add=5; scanf ("%d",&II); printf ("%d\n", A[ii]); } return 0;}
2101 Problem A Snake Filled