a53

nroot

a53
Nov 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. long long nroot(int n,long long x)
  2. {
  3. if(x<0)
  4. x=-x;
  5. else
  6. if(x==0)
  7. return 0;
  8. double m,st=0,dr=x+0.01;
  9. while(dr-st>0.01)
  10. {
  11. m=(st+dr)/2;
  12. if(pow(m,n)>x)
  13. dr=m;
  14. else
  15. st=m;
  16. }
  17. return (long long) dr;
  18. }
Add Comment
Please, Sign In to add comment