51Nod 1087 1 10 100 1000

1,10,100,1000...组成序列1101001000...,求这个序列的第N位是0还是1。
 
Input
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000)
第2 - T + 1行:每行1个数N。(1 <= N <= 10^9)
Output
共T行,如果该位是0,输出0,如果该位是1,输出1。
Input示例
3
1
2
3
Output示例
1
1
0

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <stdio.h>
 4 #include <cstring>
 5 using namespace std;
 6 #define ll long long
 7 int main()
 8 {
 9     int n;
10     cin>>n;
11     while(n--){
12         int a,s=0;
13         cin>>a;
14         for(int i=1; ;i++){
15             if(i==1) s+=i;
16             else s+=i-1;
17             if(s>a){
18                 cout<<0<<endl;
19                 break;
20             }
21             else if(s==a){
22                 cout<<1<<endl;
23                 break;
24             }
25         }
26     }
27     return 0;
28 }

 

posted @ 2017-07-26 11:35  wydxry  阅读(247)  评论(0编辑  收藏  举报
Live2D