We have been give a problem to add two numbers without the + operator and using XOR, AND and <<.
Our job is to find the total number of iterations that while loop is going to take.

What I have tried:

Python

<pre>
from sys import stdin,stdout
T = int(stdin.readline().strip())
for itr_t inrange(T):
a = (stdin.readline().strip(),2)
b = (stdin.readline().strip(),2)
print(a)
print(b)
count = 0while b != 0:
count += 1
u = a^b
v = a&b
a = u
b = v << 1print(count)

So i just used a basic counter but I want to optimise it and want to find the count without actually doing the operations over and over again.
My logic is that count = to the number of times the carry will be shifted
But I would really like some hint/advice on this one to apply a better a logic to find the count. I believe the complexity is O(1).
I know I tried this in python but I'm fine with C++ as well

Done.