Number and the Digit Sum
Submissions: 1430   Accuracy:

18.73%

  Difficulty: Easy   Marks: 2

Given a positive value N, we need to find the count of numbers smaller than and equal to N such that the difference between the number and sum of its digits is greater than or equal to given specific value k.

Input:
The first line of input contains an integer T denoting the number of test cases. Each test case contains two space separated integers N and k.

Output:
Print an integer which is the required value.

Constraints:
1<=T<=50
1<=N,k<=109

Example:
Input:

2
13 2
10 5

Output:
4
1

Explanation:

Input : N = 13, diff = 2
Output : 4
Then 10, 11, 12 and 13 satisfy the given
condition shown below,
10 – sumofdigit(10) = 9 >= 2
11 – sumofdigit(11) = 9 >= 2
12 – sumofdigit(12) = 9 >= 2
13 – sumofdigit(13) = 9 >= 2  
Whereas no number from 1 to 9 satisfies 
above equation so final result will be 4

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Shashwat Jain
Author: shashwat jain


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.