51Nod 1087 1 10 100 1000(暴力+找規律)
阿新 • • 發佈:2018-12-17
分析: 我們可以看出1出現位置的規律: 0 1=0+1 3=1+2 6=1+2+3 10=1+2+3+4 總結出1出現的位置是:滿足1+2+…n的,然後根據求和公式列舉判斷即可。 AC:
#include<bits/stdc++.h>
using namespace std;
int t,flag=0,x;
int main(){
std::ios::sync_with_stdio(false);
cin>>t;
while(t--){
flag=0;
cin>>x;
x--;
x= x*2;
//問題轉換為x能不能表示成n(n+1)的形式
for(int i=0;i<=sqrt(x)+100;i++){
if(i*i+i==x){
flag=1;
}
}
if(flag) cout<<"1"<<endl;
else cout<<"0"<<endl;
}
return 0;
}