注意,因为这里 $k$ 是整数,所以 $\sqrt{1+8n}$ 是整数是有答案的必要条件,即 $1+8n$ 必须是完全平方数。
所以代码就很好写了。放代码:
```cpp
#include<bits/stdc++.h>
#define int long long // 记得开 long long
using namespace std;
main(){
ios::sync_with_stdio(false);
int t; cin>>t;
while(t--){
int x; cin>>x;
int a=sqrt(x*8+1);
if(a*a==x*8+1)cout<<(a-1>>1)<<endl; // 如果有解那么答案就是 (a-1)/2
else cout<<"NAI\n"; // 无解情况
}
return 0;
}
```