Codeforces Round #720 (Div. 2) A:Nastia and Nearly Good Numbers&B:Nastia and a Good Array

A Nastia and Nearly Good Numbers

题大意:
输入两个数a b  ->   求x y z
且  z=x+y;
  z%a=0 && z%b=0
  x%a=0&&x%b!=0
  y%a=0&&y%b!=0

首先b=1时,无解->b不能被x和y整除
所以只要使x=a ;y=a*(2b-1) ;z=x+y 即(z=2a*b)

AC代码:

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		ll a, b;
		cin >> a >> b;
		if (b == 1)
		{
			cout << "NO" << endl;
			continue;
		}
		else
		{
			cout << "YES" << endl;
			cout << a << " " << a * (2*b - 1) << " " << 2*a * b << endl;
		}
	}
	return 0;
}

B. Nastia and a Good Array

题目大意:就是将一组数组变成相邻元素互素
但是在换数字的时候要考虑到换的两对数字其中最小的数字相同
那么我们可以先把数组中最小的提拉出来,对其进行变化

AC代码

const int mmax = 1e5;

ll a[mmax];

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int w;
		cin >> w;
		for (int i = 1; i <= w; i++)
		{
			cin >> a[i];
		}
		int pos = 1;
		for (int i = 2; i <= w; i++)
		{
			if (a[i] < a[pos])
				pos = i;
		}
		cout << w - 1 << endl;
		for (int i = pos + 1; i <= w; i++)
		{
			cout << pos << " " << i << " " << a[pos] << " " << a[pos] + (i - pos) << endl;
		}
		for (int i = 1; i < pos; i++)
		{
			cout << pos << " " << i << " " << a[pos] << " " << a[pos] + (pos - i) << endl;
		}
	}
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值