基準時間限制:1 秒 空間限制:131072 KB 分值: 5
難度:1級算法題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
#include<iostream>
#include<math.h>
#include<string>
#include<stdio.h>
#include<string.h>
using namespace std;
#define maxx 45000
int main()
{
long long a[maxx];
bool flag=false;
long long n;
int t;
cin>>t;
a[1]=1;
a[2]=2;
for(int i=3; i<maxx; i++)
{
a[i]=a[i-1]+(i-1);
}
while(t--){
cin>>n;
for(int i=0; i<maxx; i++)
{
if(n==a[i])
{
flag=true;
break;
}
}
if(flag){
cout<<"1"<<endl;
flag=false;
}
else
cout<<"0"<<endl;
}
return 0;
}