题解:P11036 【MX-X3-T3】「RiOI-4」GCD 与 LCM 问题

· · 题解

题解

原题链接

本题是作者在上英语课时推出来的,可能证明有点感性化,请见谅!

Solution

因为该题与 \gcd(a,b) 和 \operatorname{lcm}(a,b) 有关,又因为 \gcd(1,b)=1 和 \operatorname{lcm}(1,b)=b 所以我们可以大胆猜想 b=1。

我们可以注意到 \gcd(a,b)=1。

所以问题可转化为 \operatorname{lcm}(c,d)+1=a+c+d+1。

所以我们可以发现 c 和 d 均与 a 相关,且 \operatorname{lcm}(c,d)=a+c+d,不妨设 c=xa,d=yb。 所以就需要满足 \operatorname{lcm}(x,y)=x+y+1,很容易得出 x=2 与 y=3。

但如果你这么写就会喜提24pts。

#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0); 
    int T;
    cin>>T;
    while(T--){
        long long a,b=1,c,d;
        cin>>a;
        c=2*a;
        d=3*a;
        cout<<b<<" "<<c<<" "<<d<<"\n";
    }
}

所以需要把它转成奇数。

CODE

#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0); 
    int T;
    cin>>T;
    while(T--){
        long long a,k;
        cin>>a;
        k=a&-a;
        cout<<k<<" "<<2*k<<" "<<2*k+a<<"\n";
    }
}