C. Make Good

图片说明
图片说明

解法

遍历a数组,把和 跟异或值 都算出来,我们最终要做到的目的是,sum和的二进制 是 异或值yi左移1位得来的。

step1 : 添加yi,这样和就变成了sum+yi,yi就变成了0
step2 : 添加sum+yi,这样和就变成了2*(sum+yi),yi就变成了sum+yi
完成

代码

#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug_in  freopen("in.txt","r",stdin)
#define debug_out freopen("out.txt","w",stdout);
#define pb push_back
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
const ll maxn = 1e6+10;
const ll maxM = 1e6+10;
const ll inf = 1e8;
const ll inf2 = 1e17;

template<class T>void read(T &x){
    T s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    x = s*w;
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}

template <typename ... T>
void DummyWrapper(T... t){}

template <class T>
T unpacker(const T& t){
    cout<<' '<<t;
    return t;
}
template <typename T, typename... Args>
void pt(const T& t, const Args& ... data){
    cout << t;
    DummyWrapper(unpacker(data)...);
    cout << '\n';
}

//--------------------------------------------

int T,N;
int main(){
    // debug_in;

    read(T);
    while(T--){
        read(N);
        ll sum = 0,yi = 0;
        for(int i = 1;i<=N;i++) {
            ll t;read(t);
            sum += t;
            yi ^= t;
        }
        if(yi == 0){
            cout<<1<<'\n';
            cout<<sum<<'\n';
        }else{
            cout<<2<<'\n';
            cout<<yi<<" "<<sum + yi<<'\n';
        }
    }



    return 0;
}