#include<bits/stdc++.h>
using namespace std;
#define e unsigned long long int
e decimal(string an)
{
int l = an.size(), i;
e s = 0, b = 1, r = 0;
for(i=l-1;i>=0;i--)
{
r = (an[i] - 48);
s = s + (r*b);
b = b * 2;
}
return s;
}
string binary(e a)
{
string ch = "";
int r = 0;
while(a != 0)
{
r = a%2;
a = a/2;
ch += to_string(r);
}
return ch;
}
string sum(string ch, string an)
{
string ab = "";
int a, b, i, j, r;
a = ch.size();
b = an.size();
i = j = 0;
while(i<a && j<b)
{
if(ch[i] == '1' && an[j] == '1')
{
ab += '0';
}
else
{
r = (ch[i] - '0') + (an[j] - '0');
ab += to_string(r);
r = 0;
}
i++;
j++;
}
while(i<a)
ab += ch[i++];
while(j<b)
ab += an[j++];
reverse(ab.begin(), ab.end());
return ab;
}
int main()
{
e n, m;
while(cin >> n >> m)
{
string an, ar, b_sum;
an = ar = b_sum = "";
an = binary(n);
ar = binary(m);
b_sum = sum(an, ar);
e summation = decimal(b_sum);
cout << summation << endl;
}
return 0;
}
using namespace std;
#define e unsigned long long int
e decimal(string an)
{
int l = an.size(), i;
e s = 0, b = 1, r = 0;
for(i=l-1;i>=0;i--)
{
r = (an[i] - 48);
s = s + (r*b);
b = b * 2;
}
return s;
}
string binary(e a)
{
string ch = "";
int r = 0;
while(a != 0)
{
r = a%2;
a = a/2;
ch += to_string(r);
}
return ch;
}
string sum(string ch, string an)
{
string ab = "";
int a, b, i, j, r;
a = ch.size();
b = an.size();
i = j = 0;
while(i<a && j<b)
{
if(ch[i] == '1' && an[j] == '1')
{
ab += '0';
}
else
{
r = (ch[i] - '0') + (an[j] - '0');
ab += to_string(r);
r = 0;
}
i++;
j++;
}
while(i<a)
ab += ch[i++];
while(j<b)
ab += an[j++];
reverse(ab.begin(), ab.end());
return ab;
}
int main()
{
e n, m;
while(cin >> n >> m)
{
string an, ar, b_sum;
an = ar = b_sum = "";
an = binary(n);
ar = binary(m);
b_sum = sum(an, ar);
e summation = decimal(b_sum);
cout << summation << endl;
}
return 0;
}
Comments
Post a Comment