Ehab the Xorcist CodeForces - 1325D

Given 2 integers uu and vv, find the shortest array such that bitwise-xor of its elements is uu, and the sum of its elements is vv.

Input

The only line contains 2 integers uu and vv (0≤u,v≤1018)(0≤u,v≤1018).

Output

If there's no array that satisfies the condition, print "-1". Otherwise:

The first line should contain one integer, nn, representing the length of the desired array. The next line should contain nn positive integers, the array itself. If there are multiple possible answers, print any.

Examples

Input

2 4

Output

2
3 1

Input

1 3

Output

3
1 1 1

Input

8 5

Output

-1

Input

0 0

Output

0

Note

In the first sample, 3⊕1=23⊕1=2 and 3+1=43+1=4. There is no valid array of smaller length.

Notice that in the fourth sample the array is empty.

题意:就是给你2个数,求需要几个数通过异或和加法运算能得到这2个数的值.一个神奇的思维题。

解析:分类讨论:

1.当u>v时,显然无解;

2.当 u=v且 u!=0时,解为 u;

3.当 u=v且 u=0时,解为空;

4.当 u<v时,根据异或的性质,两个相同数异或结果肯定为0。

那么 v可以表示为 v=u+(v−u)/2+(v−u)/2;

但当 v−u为奇数时,不能满足,无解; 当 v−u为偶数时,显然为一个可行解。

但因为要求最小,所以要判断元素个数为 2时,是否有解。

根据异或的性质: a+b=a⨁b+2*(a&b)

即 加法=不进位加法+进位数字

令 x=(v−u)/2 有 v=u+2*x,所以 x=(a&b),u=a⨁b

当 x 的第 i 位为 1 时,那么 a,b 的第 i 位必然为 1 u 的第 i 为必然为 0,所以 x&u=0。

那么 v=u+x+x=(u+x)+x,(u+x)⨁x=u。

此时有 2 个解。如不满足(x&u)=0,则有 3 个解。

代码如下:

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<map>
#include<math.h>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
#define ll long long
int main()
{
    ll u,v;
    scanf("%lld%lld",&u,&v);
    if(u>v||((v-u)&1))
        printf("-1\n");
    else if(u==v&&u==0)
        printf("0\n");
    else if(u==v&&u!=0)
        printf("1\n%lld\n",u);
    else
    {
        ll x=(v-u)/2;
        if((x&u)==0)
            printf("2\n%lld %lld\n",u+x,x);
        else
            printf("3\n%lld %lld %lld\n",u,x,x);
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值