2 条题解
-
0
按题意直接模拟即可。(记得要特判 )
AC code:
#include <bits/stdc++.h> using namespace std; int main() { freopen("sd.in", "r", stdin); freopen("sd.out", "w", stdout); int T; cin >> T; while (T--) { long long n; cin >> n; if (n == 0) { cout << "0 0" << endl; continue; } if (n % 4 == 2) { cout << "-1 -1" << endl; continue; } long long x, y; bool found = false; for (long long b = 1; b * b <= n; ++b) { if (n % b == 0) { long long a = n / b; if ((a + b) % 2 == 0) { x = (a + b) / 2; y = (a - b) / 2; if (x <= n && y >= 0) { cout << x << " " << y << endl; found = true; break; } } } } if (!found) { cout << "-1 -1" << endl; } } return 0; } -
0
众所周知:
- 。
- 。
- 。
- 对于 无解。
- 以上式子中 为非负整数。
直接分情况讨论即可。
#include <bits/stdc++.h> using namespace std; int main() { freopen("sd.in", "r", stdin); freopen("sd.out", "w", stdout); int T; cin >> T; while (T--) { long long n; cin >> n; if (!n) { cout << "0 0" << endl; continue; } switch (n % 4) { case 0: { cout << n / 4 + 1 << ' ' << n / 4 - 1 << endl; break; } case 2: { cout << "-1 -1" << endl; break; } default: { cout << n / 2 + 1 << ' ' << n / 2 << endl; break; } } } return 0; }
- 1
信息
- ID
- 156
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 2
- 标签
- 递交数
- 52
- 已通过
- 12
- 上传者