From 23271050c21cd7a00a9f5ed3d2d2f7d84bd8a248 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 23 May 2022 21:25:41 +0800 Subject: [PATCH] =?UTF-8?q?P5596=20=E3=80=90XR-4=E3=80=91=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/76300560 --- Luogu/P5596/P5596.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Luogu/P5596/P5596.cpp diff --git a/Luogu/P5596/P5596.cpp b/Luogu/P5596/P5596.cpp new file mode 100644 index 00000000..1d5903d3 --- /dev/null +++ b/Luogu/P5596/P5596.cpp @@ -0,0 +1,61 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +long long a, b, d, m, ans; + +int main() { + std::ios::sync_with_stdio(false); + + cin >> a >> b; + + d = a * a - b * 4; + + if (d == 0) { + cout << "inf" << endl; + + exit(0); + } else if (d < 0) { + d *= -1; + m = std::sqrt(d); + + for (long long q = 1; q <= m; q++) { + if (d % q == 0) { + long long p = d / q; + + long long x = p - q - 2 * a, + y = p + q; + + if (x % 4 || y % 4) continue; + + x /= 4, y /= 4; + + if (x >= 0 && y >= x) ans++; + } + } + } else { // d > 0 + m = std::sqrt(d); + + for (long long q = 1; q <= m; q++) { + if (d % q == 0) { + long long p = d / q; + + long long x = p + q - 2 * a, + y = p - q; + + if (x % 4 || y % 4) continue; + + x /= 4, y /= 4; + + if (x >= 0 && y >= x) ans++; + } + } + } + + cout << ans << endl; + + return 0; +}