You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
typedef long long LL;
|
|
|
|
LL n, d, e;
|
|
// p^2 -(n-e*d+2)p+n = 0
|
|
bool check(LL num) { //判断num是否时完全平方数
|
|
LL t = LL(sqrt(num));
|
|
return t * t == num;
|
|
}
|
|
int main() {
|
|
int k;
|
|
cin >> k;
|
|
|
|
while (k--) {
|
|
cin >> n >> d >> e;
|
|
LL b = e * d - n - 2;
|
|
LL a = 1, c = n;
|
|
|
|
//一元二次方程无解的情况
|
|
if (b * b < 4 * a * c) {
|
|
puts("NO");
|
|
continue;
|
|
}
|
|
|
|
LL t = b * b - 4 * a * c; // t需要是一个完全平方数
|
|
bool flag = false;
|
|
if (check(t) && (LL(-b + sqrt(t)) % (2 * a) == 0)) {
|
|
LL p = (-b - sqrt(t)) / (2 * a); //两个解,一个是+,另一个就是-,小的在前就是-,大的在后就是+
|
|
//所以这里将符号变了一下
|
|
LL q = n / p;
|
|
if (p) { // p是正整数,0或负数需要否掉
|
|
flag = true;
|
|
printf("%lld %lld\n", p, q);
|
|
}
|
|
}
|
|
if (!flag) puts("NO");
|
|
}
|
|
return 0;
|
|
}
|