#P9718. Minimum Addend with Exact Carry Count
Minimum Addend with Exact Carry Count
Minimum Addend with Exact Carry Count
Given two positive integers x and k, find the minimum positive integer y such that when adding x and y using column addition in base-ten (as taught in primary school), the total number of carry operations is exactly k.
In more formal terms, let the standard addition algorithm be applied from the least significant digit to the most significant digit. In each column, if the sum of the corresponding digits (plus any carry from the previous column) is at least 10, a carry occurs. You are to determine the smallest positive integer y for which exactly $$k$$ carry operations occur when computing x+y.
Note: A carry operation refers to the process of transferring 1 to the next column when a column sum is at least 10.
inputFormat
The input consists of a single line containing two space-separated positive integers: x and k.
outputFormat
Output a single integer, which is the minimum positive integer y such that the number of carry operations in the addition x+y is exactly k.
sample
5 1
6