一个初中数学题

题意

分析

韦达定理
随便让(2+根号3)^n 和(2-根号3)^n 等于x1,x2我们得到一个方程
x^2-m*x+1=0;
先判断是否有根,无根就没有解,有根就讨论一个根和两个根的情况
用求根公式求根,再用log函数求一下

代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	double m;
	while(cin>>m){
		if(m*m-4<0){
			cout<<"No answer!\n";
			return 0;
		}
		else if(m*m==4){
			double x1=m/2;
			double ans=log(x1)/log(2+sqrt(3));
			cout<<x1<<endl;
			printf("%.9f\n",ans);
		}
		else{
			double x1=-(-m+sqrt(m*m-4))/2;
			double x2=-(-m-sqrt(m*m-4))/2;
			double ans1=log(x1)/log(2+sqrt(3));
			double ans2=log(x2)/log(2+sqrt(3));
			printf("%.9f %.9f\n",ans1,ans2);
		}
	}
	return 0;
}
posted @ 2018-10-16 22:51  ChunhaoMo  阅读(142)  评论(0)    收藏  举报