a53

PatratMagic4

a53
Jan 22nd, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. #include <cmath>
  2. long long int magic(unsigned long long int c)
  3. {
  4. if(c<15)
  5. return 0;
  6. double C=(double)c,u,s,t,d=2*sqrt(C*C+1/27);
  7. long long n=0;
  8. if(d==0)
  9. u=-C,t=cbrt(u),s=cbrt(2*C-u);
  10. if(d>0)
  11. u=(-C+sqrt(C*C+1/27)),t=cbrt(u),s=cbrt(2*C+u);
  12. n=(long long int)(s-t);
  13. if(c==1ULL*(n*n*n+n)/2)
  14. return n;
  15. return 0;
  16. }
Add Comment
Please, Sign In to add comment