Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. typedef long long ll;
  7.  
  8. ll n;
  9.  
  10. ll f(ll x) {
  11.     return abs((x * x + x) - (n * n + n) / 2);
  12. }
  13.  
  14. int main() {
  15.     cin >> n;
  16.     ll left = 0;
  17.     ll right = n + 1;
  18.     for (; left + 1 < right; ) {
  19.         ll middle = (left + right) / 2;
  20.         f(middle - 1) < f(middle) ? right = middle : left = middle;
  21.     }
  22.     cout << left << endl;
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement