c = 0
u = x ^ y
v = x and y
x = u
y = v*2
for _ in range(int(input())):
a = input()
b = input()
for i in a:
for i in b:
Why I am getting this error?
I can’t see any submissions of this code from you that resulted in a SIGTSTP - only this one, which resulted in a TLE.
Are you trying to “Run” without providing Custom Input?
First of all the solution which you are giving for the problem BINADD by first finding the decimal equivalent of the given number and then executing the steps, as it is defined in the problem statement because
python support big-integers will not pass the last test-case, and will give you TLE.
As per the posted source-code, you don’t need to convert the given binary number into decimal explicitly because in
python you can directly find the decimal equivalent usng
a = int("0b" + intput().rstrip(), base = 2)
b = int("0b" + input().rstrip(), base = 2)
Refer to the following source code:
loop_count = 0
while b != 0:
loop_count += 1
x = a ^ b
y = a & b
a = x
b = y << 1
for t in range(int(input().rstrip()):
a = int('0b' + input().rstrip(),base = 2)
b = int('0b' + input().rstrip(),base = 2)
if not b:
elif not a:
elif a == b:
if __name__ == "__main__":
Tip: Whenever you are finding the decimal equivalent of a binary number you can use the following algorithm:
binary_string = input().rstrip()
decimal_equivalent = 0
for bit in binary_string:
decimal_equivalent = 2 * decimal_equivalent + int(bit)
If you want to solve the problem under the given time-limit use the concept of Largest Carry Sequence as explained in this post.
Thanks for reading.