#GD0000174. Giảm tổng chữ số (Decrease the Sum of Digits)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Giảm tổng chữ số (Decrease the Sum of Digits)
Decrease the Sum of Digits
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given positive integers and . In one operation, you increase by exactly , and you may repeat the operation as many times as needed.
The decimal digit sum of an integer is the sum of the digits of its ordinary base-ten representation. Find the minimum number of operations required to obtain a number whose digit sum is at most .
Input
The only line contains integers , the initial number and the maximum allowed digit sum.
Output
Print one nonnegative integer: the smallest number of unit increments required.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
500 4
Output
500
Explanation
The initial number has digit sum . Every integer between and has a hundreds digit of at least , so none can satisfy the limit. The next number has digit sum and requires increments; the answer is .