洛谷 P13836
解题思路:
首先,我们要先做出 P11275 这道题。根据前面题目的结论: 时,令 即可;当 ,没有任何的两个数最小公倍数为 ,此时无解。由于题目要求 ,所以当 小于等于 ,让 , 即可;而如果 ,可以考虑 ,而这时还要判断奇数与偶数。通过画图发现,奇数情况时,,;偶数情况时,,。
AC 代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int q;
signed main() {
cin >> q;
while (q--) {
int x;
cin >> x;
if (x == 0) {
cout << "1 1" << endl;
} else if (x == 1) {
cout << "-1 -1" << endl;
} else if (x < 1e18) {
cout << 1 << " " << x << endl;
} else {
if (x % 2 == 1) {
cout << x / 2 << " " << x / 2 + 1 << endl;
} else {
cout << x / 2 - 1 << " " << x / 2 + 1 << endl;
}
}
}
return 0;
}