还有简单的方法吗?求分享
查看原帖
还有简单的方法吗?求分享
870862
liuchangjin楼主2022/11/8 19:06
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k, p, q;
	cin >> k;
	long long a[k][3];
	for(int i = 0; i < k; i++){
		for(int j = 0; j < 3; j++){
			cin >> a[i][j];
		}
	} 
	for(int i = 0; i < k; i++){
		long long t = a[i][0] - a[i][1] * a[i][2] + 2;
		long long d = t * t - 4 * a[i][0];
		double res;
		if( d < 0 ){
			cout << "NO" << endl;
			continue;
		}	
		else if( d >= 0 ){
			res = (t + sqrt(d)) / 2;
			if(res <= 0 || (res - int(res) > 0)){
				cout << "NO" << endl;
				continue;
			}
			else{
				q = res;
			}	
		}
		p = a[i][0] / q;
		if(p <= q)	cout << p << ' ' << q <<endl;
		else	cout << q << ' ' << p <<endl;
	}

	return 0;
}
2022/11/8 19:06
加载中...