Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- ll search( ll dolls){
- ll answer=0;
- ll begin=0;
- ll end = dolls-1;
- ll pa, mid;
- while(begin<=end){
- if(end==0){
- answer=1;
- break;
- }
- mid = begin + (end-begin)/2;
- pa= mid*(mid+1)/2;
- if( pa<=dolls-1){
- answer=mid;
- begin=mid+1;
- }
- else{
- end=mid-1;
- }
- }
- return answer;
- }
- int main() {
- int cases;
- cin>>cases;
- for(int i=0; i<cases; i++){
- ll doll;
- cin>>doll;
- ll answer = search(doll);
- cout<< answer<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement