I’ll analyze this problem carefully. We need to find positive integers with such that:
Let me first verify the sample and explore patterns by brute-forcing small values of .
思路
构造一组恒成立的解。取 ,并令 为 且与 互质的最小整数(即 )。
验证等式:
- 左边
- 右边
两边相等 ✓。同时 (因 ),三者均为正整数。
关于范围:,;而 是“最小的、不被 的质因子整除的数”,它不超过第一个不整除 的素数。即使 含前若干个素因子,对 而言 也极小(实测最大仅约 30),远小于 。因此该构造对所有输入都合法。
实现时只需从 开始递增找第一个 即可,每次询问复杂度极低。
C++ 代码
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
if(!(cin >> T)) return 0;
while(T--){
long long a;
cin >> a;
// b = 1, d = a, c = smallest >=2 coprime to a
long long b = 1, d = a;
long long c = 2;
while(std::gcd(a, c) != 1) ++c; // c 非常小,循环次数极少
cout << b << " " << c << " " << d << "\n";
}
return 0;
}正确性说明:当 时 ,代入原式左右均为 ,恒成立;且 、、 很小,满足全部约束。