Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- using namespace std;
- typedef long long ll;
- ll n;
- ll f(ll x) {
- return abs((x * x + x) - (n * n + n) / 2);
- }
- int main() {
- cin >> n;
- ll left = 0;
- ll right = n + 1;
- for (; left + 1 < right; ) {
- ll middle = (left + right) / 2;
- f(middle - 1) < f(middle) ? right = middle : left = middle;
- }
- cout << left << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement