二元二次方俺不会!
化简一下可以得到$p + q = n - ed + 2$
又∵$n = pq$
∴二分就很好写辣
注意不开long long见______
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
int main() {
LL k;
cin >> k;
while(k -- ) {
LL n, e, d;
cin >> n >> e >> d;
LL p = 0, q = 0, pAddq = n - e * d + 2;
LL l = 1, r = pAddq;
while(l <= r) {
int mid = l + r >> 1;
if (mid * (pAddq - mid) == n) {
p = mid;
q = pAddq - mid;
break;
}
if (mid * (pAddq - mid) > n) r = mid - 1;
else l = mid + 1;
}
if (p > q) swap(p, q);
if (p * q == n) cout << p << ' ' << q << endl;
else cout << "NO" << endl;
}
return 0;
}