题解:P11036 【MX-X3-T3】「RiOI-4」GCD 与 LCM 问题
做这道题需要用到的:The On-Line Encyclopedia of Integer Sequences, OEIS。
首先
cin >> a;
bool flg = false;
for (int b = 1; b <= 100 && !flg; ++ b )
for (int c = 1; c <= 100 && !flg; ++ c )
for (int d = 1; d <= 100 && !flg; ++ d ) {
if (a + b + c + d == __gcd(a, b) + c * d / __gcd(c, d)) {
flg = true;
cout << /*a << ' ' <<*/ b << ' ' << c << ' ' << d << '\n';
break;
}
}
你打一下表,输出所有
然后就是 OEIS 了。我们约定 x & -x。
第二列
第三列
即 $c(a) = 2^{k + 1}$,其中 $2^k \mid a$ 且 $k$ 最大。
你发现
第四列
Increase the odd part of
a to the next greater odd number to getd(a) .即设
a = b \times 2^k ,其中b 是奇数(或者说k 最大)。将b 增加到较大的下一个奇数b' 。那么d(a) = b' \times 2^k 。
显然
所以:
单词询问
#include <bits/stdc++.h>
using namespace std;
signed main() {
int T;
cin >> T;
while (T -- ) {
int a;
cin >> a;
cout << 1 << ' ' << (a & -a) * 2 << ' ' << (a & -a) * (a / (a & -a) + 2) << '\n';
}
return 0;
}