From f284d184fd1e62535bab08b7761d8bd7ceb0a763 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 10 Oct 2024 21:34:48 +0800 Subject: [PATCH] :white_check_mark: P8814 100pts --- CMakeLists.txt | 3 ++- csp-decode/main.cc | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 csp-decode/main.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 950f7a0..e212797 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,4 +24,5 @@ add_executable(Playground walking-in-maze/main.cc network-connection/main.cpp eating-snake/main.cc - insert-sort/main.cc) + insert-sort/main.cc + csp-decode/main.cc) diff --git a/csp-decode/main.cc b/csp-decode/main.cc new file mode 100644 index 0000000..30bf23b --- /dev/null +++ b/csp-decode/main.cc @@ -0,0 +1,25 @@ +#include +#include + +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; + } + } +} \ No newline at end of file