From acbf73ce315918d7700d625d23cb4ec88295948c Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sat, 25 Feb 2023 06:47:19 +0800 Subject: [PATCH] =?UTF-8?q?#1959.=20=E3=80=90cdw-2=E6=A8=A1=E6=8B=9F?= =?UTF-8?q?=E9=A2=98T1=E3=80=91=E8=A7=A3=E6=96=B9=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sjzezoj.com/submission/72541 --- S2OJ/1959/1959.cpp | 98 +++++++++++++++++++++++++++++++++++++ S2OJ/1959/data/chk.cpp | 3 ++ S2OJ/1959/data/data1.ans | 3 ++ S2OJ/1959/data/data1.in | 3 ++ S2OJ/1959/data/data2.ans | 3 ++ S2OJ/1959/data/data2.in | 3 ++ S2OJ/1959/data/data3.ans | 3 ++ S2OJ/1959/data/data3.in | 3 ++ S2OJ/1959/data/problem.conf | 3 ++ 9 files changed, 122 insertions(+) create mode 100644 S2OJ/1959/1959.cpp create mode 100644 S2OJ/1959/data/chk.cpp create mode 100644 S2OJ/1959/data/data1.ans create mode 100644 S2OJ/1959/data/data1.in create mode 100644 S2OJ/1959/data/data2.ans create mode 100644 S2OJ/1959/data/data2.in create mode 100644 S2OJ/1959/data/data3.ans create mode 100644 S2OJ/1959/data/data3.in create mode 100644 S2OJ/1959/data/problem.conf diff --git a/S2OJ/1959/1959.cpp b/S2OJ/1959/1959.cpp new file mode 100644 index 00000000..edd4a831 --- /dev/null +++ b/S2OJ/1959/1959.cpp @@ -0,0 +1,98 @@ +#include +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +std::vector> divide(long long x) { + std::vector> res; + + for (long long i = 2; i * i <= x; i++) { + if (x % i == 0) { + int cnt = 0; + + while (x % i == 0) x /= i, cnt++; + + res.emplace_back(i, cnt); + } + } + + if (x > 1) res.emplace_back(x, 1); + + return res; +} + +void solve() { + long long n; + bool flag = false; + + cin >> n; + + auto nums = divide(n); + + std::transform(nums.begin(), nums.end(), nums.begin(), [&](const std::pair &o) -> std::pair { + return {o.first, o.second << 1}; + }); + + std::function check = [&](long long x) -> bool { + long long t = x * x - n * n / x; + + if (t % 3) return false; + + long long l = 1, r = x / 2 + 1; + + while (l <= r) { + long long mid = (l + r) >> 1; + + if (mid * (x - mid) == t / 3) { + cout << x - mid << ' ' << mid << endl; + + return true; + } + + if (mid * (x - mid) > t / 3) { + r = mid - 1; + } else { + l = mid + 1; + } + } + + return false; + }; + + std::function dfs = [&](long long val, int pos) -> void { + if (flag) return; + + if (pos == nums.size()) { + if (check(val)) flag = true; + + return; + } + + for (int i = 0; i <= nums[pos].second; i++) { + dfs(val * std::pow(nums[pos].first, i), pos + 1); + } + }; + + dfs(1, 0); + + if (!flag) cout << "impossible" << endl; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + int t; + + cin >> t; + + while (t--) solve(); + + return 0; +} diff --git a/S2OJ/1959/data/chk.cpp b/S2OJ/1959/data/chk.cpp new file mode 100644 index 00000000..64e1043a --- /dev/null +++ b/S2OJ/1959/data/chk.cpp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:01f161697ce5735d84215f8768417132ea8dad7fb958059f7054fa4259f32304 +size 524 diff --git a/S2OJ/1959/data/data1.ans b/S2OJ/1959/data/data1.ans new file mode 100644 index 00000000..ec60e967 --- /dev/null +++ b/S2OJ/1959/data/data1.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:39255b4ffb00605381b65f1dc7e7d095f98d3d2aeb22182ecb8d4e437351008b +size 645 diff --git a/S2OJ/1959/data/data1.in b/S2OJ/1959/data/data1.in new file mode 100644 index 00000000..674f1fa8 --- /dev/null +++ b/S2OJ/1959/data/data1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d497d7c8759a0d98c3b036c68d963d47ff6043118419a6b6015a4479d3100374 +size 460 diff --git a/S2OJ/1959/data/data2.ans b/S2OJ/1959/data/data2.ans new file mode 100644 index 00000000..cb1b58fc --- /dev/null +++ b/S2OJ/1959/data/data2.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4aaa5c716e1f9b75a7e474355c3bfb4c96cbaced6c5463d1e260685cab99e3a8 +size 13077 diff --git a/S2OJ/1959/data/data2.in b/S2OJ/1959/data/data2.in new file mode 100644 index 00000000..adc81d77 --- /dev/null +++ b/S2OJ/1959/data/data2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bdf655e80381d2c7cb1d84d3ed43a9bd8c3fcce305712da7c8c3b5efe134994c +size 9416 diff --git a/S2OJ/1959/data/data3.ans b/S2OJ/1959/data/data3.ans new file mode 100644 index 00000000..827689fc --- /dev/null +++ b/S2OJ/1959/data/data3.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a13120ea71bdb3192cd2853e6a5a9b003adfca44e94e960d2c6bf91a787b961d +size 65155 diff --git a/S2OJ/1959/data/data3.in b/S2OJ/1959/data/data3.in new file mode 100644 index 00000000..f778c787 --- /dev/null +++ b/S2OJ/1959/data/data3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ccb79a2bc57b7cd2708b16e5c13e5abcca4c0b994a2fcee8d08fa049c7ddccc +size 46870 diff --git a/S2OJ/1959/data/problem.conf b/S2OJ/1959/data/problem.conf new file mode 100644 index 00000000..75548f46 --- /dev/null +++ b/S2OJ/1959/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8479cfcc428625f384da715fa765dc2e804cd746879b3058beffd867ed543af9 +size 291