Background of the simulation questions of Sichuan College Tom has an infinite sequence as follows:
110100100010000100000 .....
Please help Tom find the number in the specified position in this infinite sequence the first line of a positive integer n indicates the number of queries;
The next n line is a positive integer ai,ai that represents the position in the sequence. The output format is n lines, with each behavior 0 or 1, representing the number on the AI bit of the sequence. Test Sample 1 input
4
3
14
7
6
Output
0
0
1
0
Note There are n<=1500000,ai<=10^9 for 100% of the data
Tip: Arithmetic progression Sn (top N and) =n (n+1)/2 with a difference of 1
Moe-ing idea: This data is a bit large, do not consider the whole sequence of simulation to seek, you can find the law of the sequence, in its calculation. Process: Can first for the a-1+0.25, and take the whole, and then use a-sum* (sum-1)/2, so you can know that one is not 1 or 0. The code is as follows:
1#include <stdio.h>2#include <math.h>3 intMain ()4 {5 intA,sum,n;6scanf"%d",&n);7 while(n--)8 {9scanf"%d",&a);Tensum=0.5+SQRT (0.25+2* (A-1));//for the a-1+0.25, and take the whole Onea=a-sum* (sum-1)/2; A if(a==1) printf ("%d\n",1);//is 1 - Elseprintf"%d\n",0);//otherwise it's 0 . - } the return 0; -}
Infinite sequence of Tyvj-tom