Codeforces Round #819 (Div. 1 + Div. 2) and Grimoire of Code Annual Contest 2022

B. Mainak and Interesting Sequence

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Mainak has two positive integers nn and mm.

Mainak finds a sequence a1,a2,…,an of n positive integers interesting, if for all integers i (1≤i≤n), the xor of all elements in aa which are strictly less than aiai is 0. Formally if p is the bitwise XOR of all elements in a which are strictly less than ai, then a is an interesting sequence if p1=p2=…=pn=0.

For example, sequences [1,3,2,3,1,2,3], [4,4,4,4], [25] are interesting, whereas [1,2,3,4](p2=1≠0), [4,1,1,2,4] (p1=1⊕1⊕2=2≠0), [29,30,30] (p2=29≠0) aren't interesting.

Here a⊕bdenotes bitwise XOR of integers a and b.

Find any interesting sequence a1,a2,…,an (or report that there exists no such sequence) such that the sum of the elements in the sequence aa is equal to mm, i.e. a1+a2…+an=m.

As a reminder, the bitwise XOR of an empty sequence is considered to be 00.

Input

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤10^) — the number of test cases. Description of the test cases follows.

The first line and the only line of each test case contains two integers nn and mm (1≤n≤10^5 1≤m≤10^9) — the length of the sequence and the sum of the elements.

It is guaranteed that the sum of nn over all test cases does not exceed 10^5.

Output

For each test case, if there exists some interesting sequence, output "Yes" on the first line, otherwise output "No". You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).

If the answer is "Yes", output nn positive integers a1,a2,…,an(ai≥1ai≥1), forming an interesting sequence such that a1+a2…+an=m. If there are multiple solutions, output any.

Example

input

4
1 3
6 12
2 1
3 6

output

Yes
3
Yes
1 3 2 2 3 1
No
Yes
2 2 2

Note

  • In the first test case, [3] is the only interesting sequence of length 1 having sum 3.
  • In the third test case, there is no sequence of length 2 having sum of elements equal to 1, so there is no such interesting sequence.
  • In the fourth test case, p1=p2=p3=0, because bitwise XOR of an empty sequence is 0.

 

解析:

除了最大值之外其他所有的数字都出现了偶数次,因为任何数字异或偶数次自己结果一定是为0.

当n>m时显然是无解的.此外当n为偶数,但是m为奇数时也是无解的,因为n为偶数则所有的数字一定都是出现偶数次,所以所有数字的和一定是偶数,所以无解.

其他情况都是有解的,当n为奇数时,我们设置最大值有一个,n为偶数时我们设置最大值有两个(因为此时m必为偶数)其余位置填1即可.

 

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int INF=0x3f3f3f3f;
int n,m;
void solve()
{
    cin>>n>>m;
    if(n>m)
    {
        cout<<"No\n";
        return ;
    }
    if(n%2==0&&m%2)
    {
        cout<<"No\n";
        return;
    }
    cout<<"Yes\n";
    vector<int>ans(n);
    if(n&1)
    {
        for(int i=0;i<n-1;i++)
            ans[i]=1;
        ans[n-1]=m-(n-1);
    }
    else
    {
        for(int i=0;i<n-2;i++)
            ans[i]=1;
        ans[n-2]=ans[n-1]=(m-(n-2))/2;
    }
    for(auto x:ans) cout<<x<<' ';
    cout <<'\n';
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    int T;
    cin >> T;
    while(T--)
    {
        solve();
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值