Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int64_t sqrt_m(int64_t x)
- {
- int64_t res = sqrt(2 * x);
- if (res * (res + 1) > 2 * x)
- --res;
- return res;
- }
- int64_t get_sum(int64_t x)
- {
- int64_t d = sqrt_m(x);
- int64_t res = d * (d + 1) * (2 * d + 1) / 6;
- int64_t delta = d * (d + 1) / 2;
- return res + (x - delta) * (d + 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement