forked from yash982000/Competitive-Programming
-
Notifications
You must be signed in to change notification settings - Fork 1
/
makeGood1.cpp
79 lines (78 loc) · 1.11 KB
/
makeGood1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod (ll)1000000000+7
#define fast std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define input int t;cin>>t;while(t--)
int main()
{
input
{
int n;
cin>>n;
int i;
ll a[n];
ll sum=0;
ll x;
for(i=0; i<n; i++)
{
cin>>a[i];
sum+=a[i];
if(i==0)
x=a[0];
else
{
x=x^a[i];
}
}
if(sum==x*2)
{
cout<<"0\n\n";
}
else
{
if(sum%2==1)
{
ll temp=sum;
ll temp1=x;
ll cnt=1;
while(cnt<=100000)
{
temp=sum;
temp1=x;
temp+=cnt;
temp1=temp1^cnt;
if(temp==temp1*2)
{
cout<<"1\n";
cout<<cnt<<"\n";
break;
}
else
cnt=cnt+4;
}
}
if(sum%2==0)
{
ll temp=sum;
ll temp1=x;
ll cnt=2;
while(cnt<=100000)
{
temp=sum;
temp1=x;
temp+=cnt;
temp1=temp1^cnt;
if(temp==temp1*2)
{
cout<<"1\n";
cout<<cnt<<"\n";
break;
}
else
cnt=cnt+4;
}
}
}
}
}