题解:P17620 [qaswed12 OI R1] Bot Problem

· · 题解

思路

构造一组恒成立的解。假设 b=1,\ d=a ,并令 c 为 \ge 2 且与 a 互质的最小整数(即 \gcd(a,c)=1)。

验证等式:

若使两边相等。同时 b=1\ne c(因 c\ge2 ),三者均为正整数。

实现时只需从 c=2 开始递增找第一个 \gcd(a,c)=1 即可 。

#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 时 \operatorname{lcm}(a,c)=ac ,代入原式左右均为 a(c+1) ,恒成立,且a \le 10^9 , 数据较小,满足。

求赞!!