题解 | #小红的取模构造#
小红的取模构造
https://www.nowcoder.com/practice/679758a0bde0479d88463438ccee81c4
我们发现如果a和b都是正数,相同的时候无解,不同的时候只需要给小的数加上大的数即可,然后特判一下和0有关的情况
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 2e5 + 5; int __t = 1, n, a, b; void solve() { cin >> a >> b; if (a == 0 && b == 0) { cout << "1 1\n"; return; } if (a == 0) { cout << b + b << " " << b << "\n"; return; } if (b == 0) { cout << a << " " << a + a << "\n"; return; } if (a > b) { cout << a << " " << b + a << "\n"; return; } if (b > a) { cout << a + b << " " << b << "\n"; return; } cout << "-1 -1\n"; return; } int32_t main() { #ifdef ONLINE_JUDGE ios::sync_with_stdio(false); cin.tie(0); #endif cin >> __t; while (__t--) solve(); return 0; }