#B3747. Carry-Controlled Addition
Carry-Controlled Addition
Carry-Controlled Addition
Fusu gives you a nonnegative integer \(x\) and an integer \(k\). Your task is to find a nonnegative integer \(y\) such that when you add \(x+y\) using column‐addition (the standard vertical addition) exactly \(k\) carry operations occur.
In column‐addition the digits are added from right to left. In each column, if the sum of the corresponding digits (plus any carry from the previous column) is at least \(10\), then only the ones digit is written in that column and a carry of \(1\) is produced for the next column. For example, in the following addition, the two red‐highlighted digits indicate the columns in which a carry occurs:
There is one more constraint: the length (i.e. number of digits) of \(y\) must not exceed \(10^4\). It is guaranteed that when a solution exists, there is one with \(y\) having at most \(10^4\) digits.
Input and Output
Your program needs to construct one such \(y\) that meets the requirements. If there exist multiple answers, any one is acceptable. It is guaranteed that under the given input, a solution exists.
Note on the carry operation: When adding two digits \(a\) and \(b\) along with a previous carry \(c\), if \(a+b+c\ge10\), then the column produces a carry, and only the unit digit of \(a+b+c\) appears in that column.
inputFormat
The input consists of a single line containing a nonnegative integer \(x\) and an integer \(k\) (with \(0\le k\le 10^5\)), separated by a space. The integer \(x\) is given without extra leading zeros.
For example:
189 1
outputFormat
Output a nonnegative integer \(y\) (without extra leading zeros) satisfying the condition that the column‐addition of \(x+y\) produces exactly \(k\) carry operations. The length of \(y\) must not exceed \(10^4\) digits.
sample
123 1
900