#include #include #include #include using namespace std; typedef long double real; real f(real x) { return x*x*x*x*x - 4*x + 1; } real binSearch(real x1, real x2) { while (true) { real y1 = f(x1); if (y1 == 0) { return x1; } real y2 = f(x2); if (y2 == 0) { return x2; } real x = (x1 + x2)*0.5; if ((y1 > 0) == (y2 > 0) || x == x1 || x == x2) { return x; } real y = f(x); if ((y > 0) == (y1 > 0)) { x1 = x; } else { x2 = x; } } } void divide(real polynomial[], int degree, real root) { for (int i = degree; i > 0; --i) { polynomial[i - 1] += root*polynomial[i]; } for (int i = 0; i < degree; ++i) { polynomial[i] = polynomial[i + 1]; } polynomial[degree] = 0; } int main() { cout << setprecision(15); real p[] = {1, -4, 0, 0, 0, 1}; real x1 = binSearch(-2, -1); real x2 = binSearch(0, 1); real x3 = binSearch(1, 2); divide(p, 5, x1); divide(p, 5, x2); divide(p, 5, x3); real re = -0.5*p[1]/p[2]; real im = sqrt(p[0]*p[2] - p[1]*p[1]*0.25)/p[2]; cout << x1 << endl; cout << x2 << endl; cout << x3 << endl; cout << re << "+i*" << im << endl; cout << re << "-i*" << im << endl; return EXIT_SUCCESS; }