-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXOR(problem)
More file actions
54 lines (47 loc) · 1.02 KB
/
XOR(problem)
File metadata and controls
54 lines (47 loc) · 1.02 KB
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
#include<bits/stdc++.h> // find those 2 elements which are absent in the given array with n elements
using namespace std;
#define ll long long
int main()
{
ll i, n, xor1=0, xor2=0, ans, x, y, bit, num;
cin>>n;
ll a[n-2];
for(i=0; i<n-2; i++)
{
cin>>a[i];
xor1=xor1^a[i];
}
for(i=1; i<=n; i++)
{
xor1=xor1^i;
}
// cout<<xor1<<endl;
for(i=0; i<30; i++)
{
x = 1LL << i;
if((xor1 & x) != 0) /// xor1 e first kon bit e 1 ase last dik teke
{
bit = i;
num = x;
break;
}
}
// cout<<x<<endl;
for(i=0; i<n-2; i++)
{
if((a[i] & num) != 0) /// jeigula nai ogular xor 0 hbe na jei element gula array te ase ogular xor 0 ashbe
{
xor2 = xor2^a[i];
}
}
for(i=1; i<=n; i++)
{
if((i & num) != 0)
{
xor2 = xor2^i;
}
}
ans = xor1 ^ xor2; /// a^b=c b^c=a c^a=b
cout<<xor2<<" "<<ans;
return 0;
}