#include using namespace std; #include typedef boost::multiprecision::cpp_int bint; const long long linf = 4610000000000000000; int main() { bint x, n; cin >> x >> n; if (0 < x) { bint l = 0, r = n+1; while (abs(l - r) > 1) { bint c = (l + r) / 2; if (x - c * (c+1) / 2 > 0) { l = c; } else { r = c; } } if (n <= l) { cout << x - n * (n+1) / 2 << '\n'; } else { bint ans = x - l * (l+1) / 2; ans += (n - l) / 2; if ((n - l) % 2 == 1) { ans -= n; } cout << ans << '\n'; } } else { bint l = 0, r = n+1; while (abs(l - r) > 1) { bint c = (l + r) / 2; if (x + c * (c+1) / 2 <= 0) { l = c; } else { r = c; } } if (n <= l) { cout << x + n * (n+1) / 2 << '\n'; } else { bint ans = x + l * (l+1) / 2; ans -= (n - l) / 2; if ((n - l) % 2 == 1) { ans += n; } cout << ans << '\n'; } } return 0; } /* File : ~/yukicoder/526/A.cpp Date : 2025/03/07 Time : 21:02:05 */