游客 Signup | Login
中文 | En

1758 - 求指数方程的根(fxroot) [2*+] **

求指数方程的根(fxroot)
求方程f(x)=2^x+3^x-4^x=0 在[1,2]内的根。提示a^x可表示成exp(x*ln(a))或用math库中的power(a,x)。
输入:无输入
输出:f(x)=0的根,x精确到小数点10位
提示:记方程f(x)=0,若存在2个数x1和x2,且x1

Input

Output

Examples

Input


                

Output


                

Solution C++

#include <iostream>
#include <cmath>
using namespace std;
int i,j,n;
double f(double x)
{
    return(pow(2,x)+pow(3,x)-pow(4,x));
}
main()
{
      double x,r,l;
      r=2;l=1;
      x=(r+l)/2;
      while (f(x)!=0 && r-l>0.000000001)
      {
            if (f(r)*f(x)<0) l=x;
            else r=x;
            x=(r+l)/2;
      }
      printf("%0.10lf",x);
}

Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题