Answer the question
In order to leave comments, you need to log in
How to decide if the program gives the answer in the wrong format?
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main() {
double a;
int n;
cin >> a;
cin >> n;
const double eps = 1e-13;
if (a <= 0 || n == 0)
return 0;
if (n == 1 || a == 1.0)
return a;
double m, l, r;
// m = 0;
if (a > 0 and a <= 1) {
l = a;
r = 1;
}
else {
l = 1;
r = a;
}
while (r - l >= eps) {
m = (l + r) / 2.0;
if (pow(m, n) - a > 0) {
r = m;
}
else {
l = m;
}
}
cout << setprecision(12) << m;
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question