Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int bin(int n)
  4. {
  5. int num = n;
  6. int dec_value = 0;
  7. int base = 1;
  8.  
  9. int temp = num;
  10. while (temp)
  11. {
  12. int last_digit = temp % 10;
  13. temp = temp / 10;
  14.  
  15. dec_value += last_digit * base;
  16.  
  17. base = base * 2;
  18. }
  19. return dec_value;
  20. }
  21. int main()
  22. {
  23. int t;
  24. cin>>t;
  25. while(t--)
  26. {
  27. int a,b,cnt=0;
  28. cin>>a>>b;
  29. a=bin(a);
  30. b=bin(b);
  31. while(b!=0)
  32. {
  33. int U = a^b;
  34. int V = a&b;
  35. a = U;
  36. b = V * 2;
  37. cnt++;
  38. }
  39. cout<<cnt<<endl;
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement