2021-05-16 Codeforces Round #720 (Div. 2)

传送门

A. Nastia and Nearly Good Numbers

题意:构造三个数x,y, z,一个数被ab整除,另外两个数能被a整除,但不能被ab整除。因为都有a,可以将a先除掉。
要求z = x + y,b = b - 1 + 1
三个数ab, a(b-1),a
当b等于1的时候,无法构造,因为能被a整除的数也能被ab整除
能发现 b=2 时,有两个数相等,所以换成这样的三个数。
a
(b+1),a,a*b。

#include <bits/stdc++.h>
using namespace std;

const int N = 5050;
typedef long long ll;
typedef pair<int, int> PII;

int t;
ll a, b;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> t;
	while (t -- )
	{
		cin >> a >> b;
		if (b == 1)
		{
			puts("NO");
			continue;	
		}
		else
		{
			puts("YES");
			printf("%lld %lld %lld\n", a, a * b, a * (b + 1));
		}
	}
	return 0;
} 

B. Nastia and a Good Array

要保证相邻的数都是质数,我们取两个相邻的数,把大的那个数改成小的那个数加1,但是再改下去是不行的,因为随着改动各个数的大小关系在变化,所以每次改动取最小的数mi,把它旁边的数改为mi + 1, mi + 2,mi +3…

#include <bits/stdc++.h>
using namespace std;

#define INF 0x3f3f3f3f
const int N = 1e5 + 5;
typedef long long ll;
typedef pair<int, int> PII;

int t, n;
ll a[N];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> t;
	while (t -- )
	{
		cin >> n;
		for (int i = 1; i <= n; i ++ ) cin >> a[i];
		int pos, mi = INF;
		for (int i = 1; i <= n; i ++ )
		{
			if (a[i] < mi) pos = i, mi = a[i]; 
		}
		cout << n - 1 << endl;
		for (int i = 1; i < pos; i ++ )
			cout << i << ' ' << pos << ' ' << mi + pos - i << ' ' << mi << endl;
		for (int i = pos + 1; i <= n; i ++ ) 
			cout << i << ' ' << pos << ' ' << mi + i - pos << ' ' << mi << endl; 
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值