思路
构造一组恒成立的解。假设 b=1, d=a ,并令 c 为 ≥2 且与 a 互质的最小整数(即 gcd(a,c)=1)。
验证等式:
- 左边 ab+cd=a⋅1+c⋅a=a(1+c)
- 右边 lcm(a,c)+lcm(b,d)=gcd(a,c)ac+lcm(1,a)=ac+a=a(c+1)
- 即a(c+1)=a(1+gcd(a,c)c)
若使两边相等。同时 b=1=c(因 c≥2 ),三者均为正整数。
实现时只需从 c=2 开始递增找第一个 gcd(a,c)=1 即可 。
C++#include <bits/stdc++.h>
#define int long long
using namespace std;
int t;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--){
int a;
cin>>a;
int b = 1,d = a,c = 2;
while(__gcd(a,c) != 1) c++;
cout<<b<<" "<<c<<" "<<d<<endl;
}
return 0;
}
/*
假设b = 1 ,d = a;
a + cd = a*c/__gcd(a,c)+b*d/__gcd(b,d)
a(c+1) = a*c/__gcd(a,c)+a;
a(c+1) = a*(1+c/__gcd(a,c));
*/
正确性说明:当 gcd(a,c)=1 时 lcm(a,c)=ac ,代入原式左右均为 a(c+1) ,恒成立,且a≤109 , 数据较小,满足。
求赞!!