Reason
The error is because if you do input.split()
then the result will be this ['3', '5']
(let's say the input was 3 5) and a
, b
are both strings.
If you do %
with a string, you will get '3' % '5'
and it's not what you expected. This means string formatting in Python and you get the error.
you will get the same error with this:
a = '3'
b = '5'
print(a % b) # this cause the error. you will not get 3 % 5
Solution
You could do int()
every time where a
and b
appears, but It will be too hard.
Instead, try this:
n = int(input())
for i in range(n):
a, b = map(int, input().split())
if a % b != 0:
r = a % b
x = b - r
print(x)
else:
print("0")
You can use the built-in map()
function in Python and by the way, if you don't have any prompt for the input, then just leave it blank - input()
.