0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 21:48:48 +00:00

#1959. 【cdw-2模拟题T1】解方程

https://sjzezoj.com/submission/72541
This commit is contained in:
Baoshuo Ren 2023-02-25 06:47:19 +08:00
parent 3d921fdb05
commit acbf73ce31
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
9 changed files with 122 additions and 0 deletions

98
S2OJ/1959/1959.cpp Normal file
View File

@ -0,0 +1,98 @@
#include <iostream>
#include <algorithm>
#include <cmath>
#include <functional>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
std::vector<std::pair<long long, int>> divide(long long x) {
std::vector<std::pair<long long, int>> 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<long long, int> &o) -> std::pair<long long, int> {
return {o.first, o.second << 1};
});
std::function<bool(long long)> 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<void(long long, int)> 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;
}

BIN
S2OJ/1959/data/chk.cpp (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1959/data/data1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1959/data/data1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1959/data/data2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1959/data/data2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1959/data/data3.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1959/data/data3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1959/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.