A. Nastia and Nearly Good Numbers(思维)

题意
给你两个数A,B,让你构造出三个数x,y,z,其中一个数可以被AB整除,另外两个数只能被A整除,并且让z=x+y。
思路
我看到这个题的时候,就写出了一个式子。
A ∗ d + B ∗ e = A ∗ B ∗ f A*d+B*e=A*B*f Ad+Be=ABf
d + e = B ∗ f d+e=B*f d+e=Bf
让f=1的时候,d+e=B.
我们可以给d,e随意分配,只要等于B就可以。
这样为什么是可以的呢?
我们首先肯定能想到A
d肯定是能被A整除的,但是Ad是肯定小于AB的,所以Ad肯定不能被AB整除的。
当B=1的时候,输出NO,
如果B=2的时候,我们可以让f=2,然后再让d=1,e=3就可以了。
代码

#include <bits/stdc++.h>
#define ll long long
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        ll a,b;
        cin>>a>>b;
        if(b==1)
        {
            cout<<"NO"<<endl;
            continue;
        }
        cout<<"YES"<<endl;
        if(b%2==1)
        {
            cout<<a*(b/2)<<" "<<a*(b/2+1)<<" "<<a*b<<endl;
        }
        else
        {
            if(b==2) cout<<a*1<<" "<<a*3<<" "<<a*4<<endl;
            else cout<<a*(b/2-1)<<" "<<a*(b/2+1)<<" "<<a*b<<endl;
        }
    }
    return 0;
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值