A 100 [qaswed12 OI R1] Bot Problem
Our_Future · · 题解
I'll analyze this problem carefully. We need to find positive integers
Let me first verify the sample and explore patterns by brute-forcing small values of
思路
构造一组恒成立的解。取
验证等式:
- 左边
ab+cd = a\cdot 1 + c\cdot a = a(1+c) - 右边
\operatorname{lcm}(a,c)+\operatorname{lcm}(b,d) = \dfrac{ac}{\gcd(a,c)} + \operatorname{lcm}(1,a) = ac + a = a(c+1)
两边相等 ✓。同时
关于范围:
实现时只需从
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;
}
正确性说明:当