-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBINADD.cpp
More file actions
executable file
·115 lines (103 loc) · 1.84 KB
/
BINADD.cpp
File metadata and controls
executable file
·115 lines (103 loc) · 1.84 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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// #include <iostream>
// #include <sstream>
// using namespace std;
// int main()
// {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
// string a,b;
// long long t,c=0,ai,bi;
// cin>>t;
// while(t--)
// {
// cin>>a>>b;
// stringstream ssa(a);
// stringstream ssb(b);
// ssa>>ai;
// ssb>>bi;
// while(bi>0)
// {
// long u=ai^bi;
// long v=ai&bi;
// ai=u;
// bi=v*2;
// c++;
// }
// cout<<c<<"\n";
// c=0;
// }
// return 0;
// }
//
// #include <iostream>
// #include <string>
// using namespace std;
// int main()
// {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
// cout.tie(NULL);
// int t,n,i,k,mid;
// string s,temps="";
// cin>>t;
// while(t--)
// {
// cin>>n>>s;
// k=0;
// mid=n/2;
// temps=s.substr(0,mid);
// while(mid<n)
// {
// size_t found=str.find(temps,mid+1);
// if(found != string::npos)
// {
// k++;
// mid=;
// }
// }
// }
// }
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cpp_int t,a,b,i;
cin>>t;
while(t--)
{
cin>>a>>b;
a=binaryToDecimal(a);
b=binaryToDecimal(b);
cpp_int u,v;
while(b>0)
{
u=a^b;
v=a&b;
a=u;
b=v*2;
c++;
}
cout<<c<<"\n";
}
return 0;
}
cpp_int binaryToDecimal(cpp_int n)
{
cpp_int num = n;
cpp_int dec_value = 0;
// Initializing base value to 1, i.e 2^0
cpp_int base = 1;
cpp_int temp = num;
while (temp) {
cpp_int last_digit = temp % 10;
temp = temp / 10;
dec_value += last_digit * base;
base = base * 2;
}
return dec_value;
}