1649 无穷的序列

 

#include<bits/stdc++.h>
#define f(i,s,e) for(int i = s; i <= e; i++)
#define ll long long
using namespace std;
const int N = 2e6+10,inf = 0x3f3f3f3f;
int a[N],k;
int find(int x) //查找x位置是否为1
{
    int l = 1,r = k;
    while(l <= r) //二分查找
    {
        int mid = (l + r) / 2;
        if(x < a[mid]) r = mid - 1;
        else if(x > a[mid]) l = mid + 1;
        else return 1;
    }
    return 0;
}
int main()
{
    for(int i = 1; i <= 1e9; i+=k)
    {
        a[++k] = i;
    //    cout << i << endl; //查看是否正确存储了1的位置
    }
    //cout << k << endl;
    int n; cin >> n;
    while(n--)
    {
        int x; scanf("%d",&x);
        printf("%d\n",find(x));
    }
    return 0;
}

 

posted @ 2024-06-28 14:53  CRt0729  阅读(12)  评论(0编辑  收藏  举报