D. Ehab the Xorcist (XOR and relationships)

Meaning of the questions: a number of groups seeking the shortest, the number of these XOR is u, and is v.

Solution: 1, it was found for XOR parity addition and is equivalent to, the u, v parity before the same condition is met. 2, a number of exclusive or split into several numbers must not greater than the original number, so u <= v.

3、当u==v&&u==0,为0,4、u==v&&u != 0,等于u

5, u ^ 0 = 0, 3 split into consideration the number, u, (vu) / 2, (vu) / 2. Satisfied.

6, the shortest, according to a ^ b = a + b -. 2 * (a & b) assumed answer a, b a ^ b = (u ^ x) ^ x, a + b = (u + x) +. X. If u ^ x = u + x. may be combined.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define int ll
#define mod 998244353
#define gcd(m,n) __gcd(m, n)
#define rep(i , j , n) for(int i = j ; i <= n ; i++)
#define red(i , n , j)  for(int i = n ; i >= j ; i--)
#define ME(x , y) memset(x , y , sizeof(x))
int lcm(int a , int b){return a*b/gcd(a,b);}
ll quickpow(ll a , ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;b>>=1,a=a*a%mod;}return ans;}
//int euler1(int x){int ans=x;for(int i=2;i*i<=x;i++)if(x%i==0){ans-=ans/i;while(x%i==0)x/=i;}if(x>1)ans-=ans/x;return ans;}
//const int N = 1e7+9; int vis[n],prime[n],phi[N];int euler2(int n){ME(vis,true);int len=1;rep(i,2,n){if(vis[i]){prime[len++]=i,phi[i]=i-1;}for(int j=1;j<len&&prime[j]*i<=n;j++){vis[i*prime[j]]=0;if(i%prime[j]==0){phi[i*prime[j]]=phi[i]*prime[j];break;}else{phi[i*prime[j]]=phi[i]*phi[prime[j]];}}}return len}
#define INF  0x3f3f3f3f
#define PI acos(-1)
#define pii pair<int,int>
#define fi first
#define se second
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define size(v) (int)(v.size())
#define cin(x) scanf("%lld" , &x);
const int N = 1e7+9;
const int maxn = 2e5+9;
const double esp = 1e-6;
 
 
void solve(){
    you and, v;
    cin >> u >> v ;
    if(u > v || u % 2 != v % 2){
        cout << -1 << endl;
        return;
    }
    if(u == v && v == 0){
        cout << u << endl;
        return;
    }
    if(u == v && v != 0){
        cout << 1 << endl << u << endl;
        return ;
    }
    int a = (v - u) / 2 ;
    if((a ^ u) == a + u){
        cout << 2 << endl;
        cout << (u + v) / 2 << " " << a << endl;
    }else{
        cout << 3 << endl;
        cout << u << " " << a << " " << a << endl;
    }
}
 
signed main()
{
    //ios::sync_with_stdio(false);
    int t ;
    //scanf("%lld" , &t);
    //while(t--)
        solve();
}

  

 

Guess you like

Origin www.cnblogs.com/nonames/p/12536385.html