Codeforces Round #720 (Div. 2)

A. Nastia and Nearly Good Numbers

Nastia has 2 positive integers A and B. She defines that:

The integer is good if it is divisible by A⋅B;
Otherwise, the integer is nearly good, if it is divisible by A.
For example, if A=6 and B=4, the integers 24 and 72 are good, the integers 6, 660 and 12 are nearly good, the integers 16, 7 are neither good nor nearly good.

Find 3 different positive integers x, y, and z such that exactly one of them is good and the other 2 are nearly good, and x+y=z.

Input
The first line contains a single integer t (1≤t≤10000) — the number of test cases.

The first line of each test case contains two integers A and B (1≤A≤106, 1≤B≤106) — numbers that Nastia has.

Output
For each test case print:

“YES” and 3 different positive integers x, y, and z (1≤x,y,z≤1018) such that exactly one of them is good and the other 2 are nearly good, and x+y=z.
“NO” if no answer exists.
You can print each character of “YES” or “NO” in any case.
If there are multiple answers, print any.

Example
inputCopy
3
5 3
13 2
7 11
outputCopy
YES
10 50 60
YES
169 39 208
YES
28 154 182
Note
In the first test case: 60 — good number; 10 and 50 — nearly good numbers.

In the second test case: 208 — good number; 169 and 39 — nearly good numbers.

In the third test case: 154 — good number; 28 and 182 — nearly good numbers.

在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t; cin>>t;
	while(t--){
		ll a,b; cin>>a>>b;
		if(b==1) cout<<"NO"<<endl;
		else {
			cout<<"YES"<<endl<<a*b<<" "<<a<<" "<<a*(b+1)<<endl;
		}
	}
	return 0;
}



B. Nastia and a Good Array

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Nastia has received an array of n positive integers as a gift.

She calls such an array a good that for all i (2≤i≤n) takes place gcd(ai−1,ai)=1, where gcd(u,v) denotes the greatest common divisor (GCD) of integers u and v.

You can perform the operation: select two different indices i,j (1≤i,j≤n, i≠j) and two integers x,y (1≤x,y≤2⋅109) so that min(ai,aj)=min(x,y). Then change ai to x and aj to y.

The girl asks you to make the array good using at most n operations.

It can be proven that this is always possible.

Input
The first line contains a single integer t (1≤t≤10000) — the number of test cases.

The first line of each test case contains a single integer n (1≤n≤105) — the length of the array.

The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — the array which Nastia has received as a gift.

It’s guaranteed that the sum of n in one test doesn’t exceed 2⋅105.

Output
For each of t test cases print a single integer k (0≤k≤n) — the number of operations. You don’t need to minimize this number.

In each of the next k lines print 4 integers i, j, x, y (1≤i≠j≤n, 1≤x,y≤2⋅109) so that min(ai,aj)=min(x,y) — in this manner you replace ai with x and aj with y.

If there are multiple answers, print any.

Example
inputCopy
2
5
9 6 3 11 15
3
7 5 13
outputCopy
2
1 5 11 9
2 5 7 6
0
Note
Consider the first test case.

Initially a=[9,6,3,11,15].

In the first operation replace a1 with 11 and a5 with 9. It’s valid, because min(a1,a5)=min(11,9)=9.

After this a=[11,6,3,11,9].

In the second operation replace a2 with 7 and a5 with 6. It’s valid, because min(a2,a5)=min(7,6)=6.

After this a=[11,7,3,11,6] — a good array.

In the second test case, the initial array is already good.

在这里插入图片描述

//gcd(x,x+1)==1
//最小数一定会被留下
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9+10;
int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t; cin>>t;
	while(t--){
		int n; cin>>n;
		int mi=inf ,pos=0;
		for(int i=0; i<n; i++){
			int x; cin>>x;
			if(x<mi) mi=x,pos=i;
		}
		cout<<n-1<<endl;
		for(int i=0; i<n; i++){
			if(i==pos) continue;
			cout<<pos+1<<" "<<i+1<<" "<<mi<<" "<<mi+abs(pos-i)<<endl;
		}
	}
	return 0;
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值