思路:
规律很明显是等差数列+1.那么只要判断是否是其中等差数列某个值就行。二分
#include <iostream>
#include <stdio.h>
using namespace std;
typedef long long ll;
int n;
int judge(ll x)
{
long long a=x*(x-1)/2+1;
if(a==n)
return 0;
if(a<n)
return -1;
return 1;
}
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n;
ll l=1,r=1000000000;
ll mid;
while(l<=r)
{
mid=(l+r)/2;
int tep=judge(mid);
if(tep==0)
{
cout<<1<<endl;
break;
}
else
{
if(tep==-1)
{
l=mid+1;
}
else
{
r=mid-1;
}
}
}
if(l>r)
{
cout<<"0"<<endl;
}
}
return 0;
}