/*
* Bisection Method.
* x^2 - a = 0
*/
#include <iostream>
using namespace std;
double EPS = 0.00001;
double f(double x, int a) {
return x * x - a;
}
double divideEtImpera(double lo, double hi, int a) {
if(hi - lo <= EPS) return (lo + hi) / 2;
else {
double m = (lo + hi) / 2;
//cout<<m<<endl;
if(f(lo,a) * f(m,a) < 0) {
return divideEtImpera(lo, m, a);
} else {
return divideEtImpera(m, hi, a);
}
}
}
//Bisection method using iteration
void bisection(double lo, double hi, double a) {
double m;
while((hi - lo) >= EPS) {
m = (lo + hi) / 2;
if(f(lo, a) * f(m, a) < 0) {
hi = m;
} else {
lo = m;
}
cout<<m<<endl;
}
cout<<m<<endl;
}
//Bisection method using iteration - version 2
void bisection2(double lo, double hi, double a) {
double m, y_x, y_m;
while((hi - lo) >= EPS) {
m = (lo + hi) / 2;
y_x = lo * lo - a;
y_m = m * m - a;
if( (y_x > 0 && y_m < 0) || (y_x < 0 && y_m > 0)) {
hi = m;
} else {
lo = m;
}
cout<<m<<endl;
}
cout<<m<<endl;
}
int main(int argc, char const *argv[]) {
int a;
cin>>a;
cout<<divideEtImpera(0, a + 5, a)<<endl;
bisection(0, a + 5, a);
bisection2(0, a + 5, a);
return 0;
}
LyoKICogQmlzZWN0aW9uIE1ldGhvZC4KICogeF4yIC0gYSA9IDAKICovCiNpbmNsdWRlIDxpb3N0cmVhbT4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpkb3VibGUgRVBTID0gMC4wMDAwMTsKCmRvdWJsZSBmKGRvdWJsZSB4LCBpbnQgYSkgewoKICAgICAgIHJldHVybiB4ICogeCAtIGE7Cn0KCmRvdWJsZSBkaXZpZGVFdEltcGVyYShkb3VibGUgbG8sIGRvdWJsZSBoaSwgaW50IGEpIHsKCiAgICBpZihoaSAtIGxvIDw9IEVQUykgcmV0dXJuIChsbyArIGhpKSAvIDI7CgogICAgZWxzZSB7CgogICAgICAgICBkb3VibGUgbSA9IChsbyArIGhpKSAvIDI7CiAgICAgICAgIC8vY291dDw8bTw8ZW5kbDsKICAgICAgICAgaWYoZihsbyxhKSAqIGYobSxhKSA8IDApIHsKCiAgICAgICAgICAgIHJldHVybiBkaXZpZGVFdEltcGVyYShsbywgbSwgYSk7CgogICAgICAgICB9IGVsc2UgewoKICAgICAgICAgICAgcmV0dXJuIGRpdmlkZUV0SW1wZXJhKG0sIGhpLCBhKTsKICAgICAgICAgfQogICAgfQp9CgovL0Jpc2VjdGlvbiBtZXRob2QgdXNpbmcgaXRlcmF0aW9uCnZvaWQgYmlzZWN0aW9uKGRvdWJsZSBsbywgZG91YmxlIGhpLCBkb3VibGUgYSkgewoKICAgICBkb3VibGUgbTsKCiAgICAgd2hpbGUoKGhpIC0gbG8pID49IEVQUykgewoKICAgICAgICAgIG0gPSAobG8gKyBoaSkgLyAyOwoKICAgICAgICAgIGlmKGYobG8sIGEpICogZihtLCBhKSA8IDApIHsKCiAgICAgICAgICAgICAgIGhpID0gbTsKCiAgICAgICAgICB9IGVsc2UgewoKICAgICAgICAgICAgICAgbG8gPSBtOwogICAgICAgICAgfQoKICAgICAgICAgIGNvdXQ8PG08PGVuZGw7CiAgICAgfQoKICAgICBjb3V0PDxtPDxlbmRsOwp9CgoKLy9CaXNlY3Rpb24gbWV0aG9kIHVzaW5nIGl0ZXJhdGlvbiAtIHZlcnNpb24gMgp2b2lkIGJpc2VjdGlvbjIoZG91YmxlIGxvLCBkb3VibGUgaGksIGRvdWJsZSBhKSB7CgogICAgIGRvdWJsZSBtLCB5X3gsIHlfbTsKCiAgICAgd2hpbGUoKGhpIC0gbG8pID49IEVQUykgewoKICAgICAgICAgIG0gPSAobG8gKyBoaSkgLyAyOwoKICAgICAgICAgIHlfeCA9IGxvICogbG8gLSBhOwogICAgICAgICAgeV9tID0gbSAqIG0gLSBhOwoKICAgICAgICAgIGlmKCAoeV94ID4gMCAmJiB5X20gPCAwKSB8fCAoeV94IDwgMCAmJiB5X20gPiAwKSkgewoKICAgICAgICAgICAgICAgaGkgPSBtOwoKICAgICAgICAgIH0gZWxzZSB7CgogICAgICAgICAgICAgICBsbyA9IG07CiAgICAgICAgICB9CgogICAgICAgICAgY291dDw8bTw8ZW5kbDsKICAgICB9CgogICAgIGNvdXQ8PG08PGVuZGw7Cn0KCmludCBtYWluKGludCBhcmdjLCBjaGFyIGNvbnN0ICphcmd2W10pIHsKICBpbnQgYTsKICBjaW4+PmE7CiAgY291dDw8ZGl2aWRlRXRJbXBlcmEoMCwgYSArIDUsIGEpPDxlbmRsOwogIGJpc2VjdGlvbigwLCBhICsgNSwgYSk7CiAgYmlzZWN0aW9uMigwLCBhICsgNSwgYSk7CiAgcmV0dXJuIDA7Cn0=