Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. int64_t sqrt_m(int64_t x)
  2. {
  3. int64_t res = sqrt(2 * x);
  4. if (res * (res + 1) > 2 * x)
  5. --res;
  6.  
  7. return res;
  8. }
  9.  
  10. int64_t get_sum(int64_t x)
  11. {
  12. int64_t d = sqrt_m(x);
  13. int64_t res = d * (d + 1) * (2 * d + 1) / 6;
  14. int64_t delta = d * (d + 1) / 2;
  15. return res + (x - delta) * (d + 1);
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement