题解 | #游游的最小公倍数#
游游的最小公倍数
https://www.nowcoder.com/practice/385c7aa397e54bb58f36286ab0d65156
lcm尽可能大,代表gcd尽可能小,所以一定是a和b互质时的 a*b 是最大的lcm,同时因为是二者的乘积,所以二者要尽可能的靠近 n/2 才行,所以从中间情况开始检查这一组a和b是否合法即可
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5;
int __t = 1, n;
void solve() {
cin >> n;
int a = n / 2, b = n - a;
while (__gcd(a, b) != 1)
a--, b++;
cout << a << ' ' << b << '\n';
return;
}
int32_t main() {
#ifdef ONLINE_JUDGE
ios::sync_with_stdio(false);
cin.tie(0);
#endif
cin >> __t;
while (__t--)
solve();
return 0;
}
查看13道真题和解析
