1328A. Divisibility Problem
math, 800, https://codeforces.com/problemset/problem/1328/A
You are given two positive integers 𝑎 and 𝑏. In one move you can increase 𝑎 by 1 (replace 𝑎 with 𝑎+1). Your task is to find the minimum number of moves you need to do in order to make 𝑎 divisible by 𝑏. It is possible, that you have to make 0 moves, as 𝑎 is already divisible by 𝑏. You have to answer 𝑡 independent test cases.
Input
The first line of the input contains one integer
The only line of the test case contains two integers 𝑎a and
Output
For each test case print the answer — the minimum number of moves you need to do in order to make 𝑎a divisible by 𝑏b.
Example
Input
5
10 4
13 9
100 13
123 456
92 46Output
2
5
4
333
0逐步加1尝试,会超时。
python
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
res = a % b
if res == 0:
print(0)
else:
print(b - res)