#if __INCLUDE_LEVEL__ == 0 #include __BASE_FILE__ void Solve() { int64_t x0, n; IN(x0, n); if (x0 > 0) { // x0 以上 int64_t ng = 0; int64_t ok = 1.5e9; while (ng + 1 < ok) { int64_t mid = midpoint(ng, ok); (mid * (mid + 1) / 2 >= x0 ? ok : ng) = mid; } if (n <= ok) { x0 -= n * (n + 1) / 2; OUT(x0); return; } x0 -= ok * (ok + 1) / 2; assert(x0 <= 0); // ok+1, ..., n if ((n - ok) % 2 == 0) { x0 -= (n - ok) / 2; } else { x0 -= (n - ok - 1) / 2; x0 += n; } OUT(x0); } else { // -x0 より大 int64_t ng = 0; int64_t ok = 1.5e9; while (ng + 1 < ok) { int64_t mid = midpoint(ng, ok); (mid * (mid + 1) / 2 > -x0 ? ok : ng) = mid; } if (n <= ok) { x0 += n * (n + 1) / 2; OUT(x0); return; } x0 += ok * (ok + 1) / 2; assert(x0 > 0); // ok+1, ..., n if ((n - ok) % 2 == 0) { x0 += (n - ok) / 2; } else { x0 += (n - ok - 1) / 2; x0 -= n; } OUT(x0); } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); Solve(); } #elif __INCLUDE_LEVEL__ == 1 #include template concept MyRange = std::ranges::range && !std::convertible_to; template concept MyTuple = std::__is_tuple_like::value && !MyRange; namespace std { istream& operator>>(istream& is, MyRange auto&& r) { for (auto&& e : r) is >> e; return is; } istream& operator>>(istream& is, MyTuple auto&& t) { apply([&](auto&... xs) { (is >> ... >> xs); }, t); return is; } ostream& operator<<(ostream& os, MyRange auto&& r) { auto sep = ""; for (auto&& e : r) os << exchange(sep, " ") << e; return os; } ostream& operator<<(ostream& os, MyTuple auto&& t) { auto sep = ""; apply([&](auto&... xs) { ((os << exchange(sep, " ") << xs), ...); }, t); return os; } } // namespace std using namespace std; #define IN(...) (cin >> forward_as_tuple(__VA_ARGS__)) #define OUT(...) (cout << forward_as_tuple(__VA_ARGS__) << '\n') #endif // __INCLUDE_LEVEL__ == 1