题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1087
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, 3, 6, 10, 15, 21,,,,,都是1,满足规律就是1:, 不满足就是0
代码:
#include<bits/stdc++.h>
#define N 50009
using namespace std;
typedef long long LL;
LL a[N], cnt;
void init()
{
int i;
a[0] = 0;
for(i = 1; i < N; i++)
{
a[i] = a[i - 1] + i;
if(a[i] >= 1000000000) break;
}
cnt = i;
}
int main()
{
init();
int n, t, i;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
for(i = 1; i < cnt; i++)
{
if(a[i] > n) break;
}
n = n % a[i - 1];
if(n == 1) puts("1");
else puts("0");
}
return 0;
}