1409D.md (1065B)
1 Source: https://codeforces.com/problemset/problem/1409/D 2 3 D. Decrease the Sum of Digits 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 You are given a positive integer $n$. In one move, you can increase $n$ by one (i.e. make $n := n + 1$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. 22 23 You have to answer $t$ independent test cases. 24 25 Input 26 27 The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow. 28 29 The only line of the test case contains two integers $n$ and $s$ ($1 \le n \le 10^{18}$; $1 \le s \le 162$). 30 31 Output 32 33 For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $n$ be less than or equal to $s$. 34 35 Example 36 37 Input 38 39 ``` 40 5 41 2 1 42 1 1 43 500 4 44 217871987498122 10 45 100000000000000001 1 46 ``` 47 48 Output 49 50 ``` 51 8 52 0 53 500 54 2128012501878 55 899999999999999999 56 ```