• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Mar 15th, 2017 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <bits/stdc++.h>
2. #include <unordered_map>
3. #include <utility>
4.
5. #define pb push_back
6. #define mp make_pair
7. #define F first
8. #define S second
9. #define ll long long int
10.
11. #define DEBUG(x) cout << '>' << #x << ':' << x << endl;
12. #define REP(i,n) for(ll i=0;i<(n);i++)
13. #define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
14. #define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
15.
16. #define all(v) (v).begin(),(v).end()
17.
18. inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
19. const ll INF = 1<<29;
20. inline ll two(ll n) { return 1 << n; }
21. inline ll test(ll n, ll b) { return (n>>b)&1; }
22. inline void setBit(ll & n, ll b) { n |= two(b); }
23. inline void unsetBit(ll & n, ll b) { n &= ~two(b); }
24. inline ll last_bit(ll n) { return n & (-n); }
25. inline ll ones(ll n) { ll res = 0; while(n && ++res) n-=n&(-n); return res; }
26.
27. inline int parent(int x){return floor((x-1)/2);};
28. inline int left(int x) {return 2*x+1;};
29. inline int right(int x){return 2*x+2;};
30.
31. inline bool sortDown(ll x,ll y){return x>y;}
32. inline bool sortPairSecond( std::pair< ll,ll > p1, std::pair< ll,ll > p2){ return p1.S>p2.S;}
33. inline bool sortDownByLen( std::pair< ll,ll > p1, std::pair< ll,ll > p2 ){ return p1.S-p1.F > p2.S-p2.F;}
34.
35.
36. #define MOD 1000000007
37. using namespace std;
38. /////////////////////////////////////////////////////////////////////
39.
40.
41.
42. int main()
43. {
44.     std::ios::sync_with_stdio(false);
45.
46.     ll n,m; cin>>n>>m;
47.
48.     if(m>=n){
49.         cout<<n<<endl;
50.     }
51.     else{
52.         ll hi,lo;
53.         hi=n;
54.         lo=m;
55.         bool flag=false;
56.
57.         // DEBUG(n-m);
58.
59.         while(hi-lo>1){
60.             ll mid=(hi+lo)/2;
61.
62.             if((n-m-((mid*(mid+1))/2)) >0){
63.                 lo=mid;
64.             }
65.             else if((n-m-((mid*(mid+1))/2))==0){
66.                 flag=true;
67.                 hi=mid;
68.                 break;
69.             }
70.             else{
71.                 hi=mid;
72.             }
73.         }
74.
75.         if(flag){
76.             cout<<m+hi<<endl;
77.             return 0;
78.         }
79.
80.         // DEBUG(hi);
81.         // DEBUG(lo);
82.
83.         // DEBUG((lo*(lo+1)/2));
84.
85.         if((n-m-((lo*(lo+1))/2))==0){
86.             // cout<<"hi"<<endl;
87.             cout<<m+lo<<endl;
88.         }
89.         else{
90.             cout<<m+hi<<endl;
91.         }
92.     }
93.
94. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top