'commit'
This commit is contained in:
43
TangDou/CSP-J/J2-2022/decode.cpp
Normal file
43
TangDou/CSP-J/J2-2022/decode.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#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() {
|
||||
freopen("data.in","r", stdin);
|
||||
freopen("user.out","w",stdout);
|
||||
|
||||
int k;
|
||||
scanf("%d", &k);
|
||||
|
||||
while (k--) {
|
||||
scanf("%lld %lld %lld", &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;
|
||||
}
|
||||
Reference in New Issue
Block a user