Codeforces Round #720 (Div. 2)AB题

Codeforces Round #720 (Div. 2)AB题
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.
题意:给定两个整数a,b,找三个数x,y,z,使得x+y=z并且三个数中有两个数能被a整除,有一个数能被ab整除(x,y,z各不相同)
即有a
b|z、a|x、a|y,根据题意显然b等于1时找不到这样的解(x,y能被a整除就能被ab整除),考虑b!=1的情况假设有z=k3ab;
y=a
k2,x=ak1;有x+y=z即k1+k2=bk3,由于只需要任意一种答案,我们取k3=2,k1=1;则x=a,y=(2b-1)a,z=2ab;
代码:

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
#define reset(x) memset(x, 0, sizeof(x))
#define Q_in_out ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
int solve()
{
    ll a,b;
    cin>>a>>b;
    int k1,k2;
    if(b==1){
        cout<<"NO";
        return 0;
    }
    cout<<"YES"<<endl;
    cout<<a<<' '<<a*(2*b-1)<<' '<<a*b*2;
    return 0;
}
int main()
{
    Q_in_out 
    int t;
    cin >> t;
    // t=1;
    while (t--)
    {
        solve();
        cout<<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.
题意:给定一个长度为n的数组,要求在n步以内的变换使整个数组满足:对于所有a[i]、a[i+1],两者互素,每一次的变换你可以任选i,j
i!=j,然后选定x,y将x,y替换a[i],a[j],x,y选定条件为min(x,y)=min(a[i],a[j]);
看完大佬的巧妙思路后,惊呼:妙啊~大概意思:找一个很大的素数,比数组里任意一个素数都打,再用这个素数往原数组里每隔一个数插一个
这样就能保证两两之间都是互素的,然后观摩数据发现a[i]范围是1e9,果断找了一个比1e9大的素数,第一个就是1e9+7;总的操作次数是n/2
代码:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
#define reset(x) memset(x, 0, sizeof(x))
#define Q_in_out ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
int a[N];
const ll pri = 1e9+7;
int solve()
{
    reset(a);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    cout<<n/2<<endl;
    for(int i=0;i<n-1;i+=2){
        cout<<i+1<<' '<<i+2<<' '<<min(a[i],a[i+1])<<' '<<pri<<endl;
    }
    return 0;
}
int main()
{
    Q_in_out 
    int t;
    cin>>t;
    while (t--)
    {
        solve();
        // cout<<endl;
    }
    return 0;
}

C题交互劝退…

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值