P8814 100pts

This commit is contained in:
LittleSheep 2024-10-10 21:34:48 +08:00
parent 64e55d4c4b
commit f284d184fd
2 changed files with 27 additions and 1 deletions

View File

@ -24,4 +24,5 @@ add_executable(Playground
walking-in-maze/main.cc walking-in-maze/main.cc
network-connection/main.cpp network-connection/main.cpp
eating-snake/main.cc eating-snake/main.cc
insert-sort/main.cc) insert-sort/main.cc
csp-decode/main.cc)

25
csp-decode/main.cc Normal file
View File

@ -0,0 +1,25 @@
#include <iostream>
#include <cmath>
using namespace std;
#define ll long long
int main() {
ll k;
cin >> k;
while (k--) {
ll n, d, e;
cin >> n >> d >> e;
ll base1 = n - e * d + 2;
ll var1 = sqrt(base1 * base1 - 4 * n);
ll var2 = n - e * d + 2;
ll p = (var2 + var1) / 2;
ll q = var2 - p;
if (p * q == n && e * d == (p - 1) * (q - 1) + 1 && p && q) {
cout << min(p, q) << " " << max(p, q) << endl;
} else {
cout << "NO" << endl;
}
}
}