Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define ll long long
- using namespace std;
- ll function_value(ll n)
- {
- return (n*(n+1))/2;
- }
- ll find_num(ll y)
- {
- ll l=1,r=100000;
- bool flg=0;
- while(l<=r)
- {
- ll mid=(l+r)/2;
- if(function_value(mid)==y)
- {
- flg=1;
- return mid;
- }
- else if(function_value(mid)<y)
- {
- l=mid+1;
- }
- else r=mid-1;
- }
- if(flg==0) return -1;
- }
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- ll y;
- cin>>y;
- if(find_num(y)==-1) cout<<"NAI\n";
- else cout<<find_num(y)<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement