40分求助(用的韦达定理)
查看原帖
40分求助(用的韦达定理)
559506
BestFriend楼主2022/10/30 19:25

Code:

#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<math.h>
#include<iomanip>
#include<ostream>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
ll k;
ll n,d,e;
int main(){
	scanf("%lld",&k);
	for(int i=0;i<k;i++){
		scanf("%lld%lld%lld",&n,&d,&e);
		//p*q=n
		//p+q=(n+2-e*d)
		ll x=(n+2-e*d);
		//x^2-(n+2-e*d)x+n
		//dt=(n+2-e*d)^2-4*n
		ll dt=(n+2-e*d)*(n+2-e*d)-4*n;
		if(dt<0){//求根公式 
//			printf("%lld %lld %lld\n",n,d,e);
			puts("NO");
			continue;
		}
		if(sqrt(dt)*sqrt(dt)!=dt){
//			printf("%lld %lld %lld\n",n,d,e);
			puts("NO");
			continue;
		}
		ll u=sqrt(dt);
		ll b=n+2-e*d;
		printf("%lld %lld\n",(b-u)/2,(b+u)/2);
	}
	return 0;
}

thank you

2022/10/30 19:25
加载中...