fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. double calculatePower(double base, int exponent){
  5. double res=1.0;
  6. while(exponent > 0){
  7. if(exponent%2==1){
  8. res=res*base;
  9. }
  10. base=base*base;
  11. exponent=exponent/2.0;
  12. }
  13. return res;
  14. }
  15. int main() {
  16. double m;
  17. int n;
  18. cin>>n>>m;
  19. double low=0.0, high=m;
  20. double eps=1e-6;
  21.  
  22. while(high-low>eps){
  23. double mid=(low+high)/2.0;
  24. if(calculatePower(mid, n)<m)
  25. low=mid;
  26. else
  27. high=mid;
  28. }
  29. cout<<low;
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5324KB
stdin
3 8 
stdout
2