Minimum Addition to Make Integer Beautiful
You are given two positive integers n and target.
An integer is considered beautiful if the sum of its digits is less than or equal to target.
Return the minimum non-negative integer x such that n + x is beautiful. The input will be generated such that it is always possible to make n beautiful.
Example 1
Input
n = 16, target = 6Output
4Initially
n is 16 and its digit sum is 7; after adding 4, n becomes 20 with digit sum 2, and no smaller non-negative addition works.Example 2
Input
n = 467, target = 6Output
33Initially
n is 467 and its digit sum is 17; after adding 33, n becomes 500 with digit sum 5, and no smaller non-negative addition works.Constraints
- 1 <= n <= 10^12
- 1 <= target <= 150
- The input will be generated such that it is always possible to make
nbeautiful.