#B4120. Minimum Increment to Achieve Desired Units Digit
Minimum Increment to Achieve Desired Units Digit
Minimum Increment to Achieve Desired Units Digit
Given a two-digit integer \(a\) and a single digit \(b\), your task is to determine the minimum non-negative integer \(x\) that needs to be added to \(a\) in order to make the units (ones) digit of \(a+x\) equal to \(b\). It is allowed that \(x=0\) if the condition is already satisfied.
In mathematical terms, let \(r = a \bmod 10\). You need to find the smallest \(x \ge 0\) such that:
[ (a + x) \bmod 10 = b ]
This can be computed by the formula:
[ x = (b - (a \bmod 10) + 10) \bmod 10 ]
Note: \(a\) is guaranteed to be a two-digit number and \(b\) is a digit (0-9).
inputFormat
The input consists of a single line containing two integers \(a\) and \(b\) separated by a space.
- a: a two-digit integer (10 ≤ a ≤ 99).
- b: an integer representing the desired units digit (0 ≤ b ≤ 9).
outputFormat
Output a single integer representing the minimum non-negative integer \(x\) such that when added to \(a\), the units digit of the result equals \(b\).
sample
47 7
0