fork download
  1. #include <iostream>
  2. using namespace std;
  3. double calculatePower(double base, int exponent){
  4. double result=1.0;
  5. for(int i=1;i<=exponent;i++)
  6. result=result*base;
  7. return result;
  8. }
  9.  
  10. int main() {
  11. double m;
  12. int n;
  13. cin>>n>>m;
  14.  
  15. double low=0.0,high=m;
  16. double eps = 1e-6; // Precision threshold 'p' (accurate to 6 decimal places)
  17. while(high-low > eps){
  18. double mid = (low + high)/2.0;
  19. if(calculatePower(mid, n)<m)
  20. low=mid;
  21. else
  22. high=mid;
  23. }
  24. cout<<low;
  25. return 0;
  26. }
Success #stdin #stdout 0s 5320KB
stdin
2 2
stdout
1.41421