Digit Removal solution codechef

Digit Removal solution codechef

You are given an integer NN and a digit DD. Find the minimum integer you should add to NN such that the final value of NN does not contain the digit DD.

Input Format Digit Removal solution codechef

  • The first line contains TT denoting the number of test cases. Then the test cases follow.
  • Each test case contains two integers NN and DD on a single line denoting the original number and the digit you need to avoid.

Output Format Digit Removal solution codechef

For each test case, output on a single line the minimum integer you should add to NN.

Constraints Digit Removal solution codechef

  • 1T1051≤T≤105
  • 1N1091≤N≤109
  • 0D90≤D≤9

Subtasks Digit Removal solution codechef

  • Subtask 1 (100 points): Original constraints

Sample Input 1 

5
21 5
8 8
100 0
5925 9
434356 3

Sample Output 1  Digit Removal solution codechef

0
1
11
75
5644

Explanation Digit Removal solution codechef

Test case 11: N=21N=21 does not contain the digit D=5D=5. Hence there is no need to add any integers to NN.

Test case 22: If 11 is added to N=8N=8, it becomes equal to 99, which does not contain the digit D=8D=8.

Test case 33: The minimum integer you should add to N=100N=100 such that the final value of NN does not contain the digit D=0D=0 is 1111.

Test case 55: The minimum integer which is greater than 434356434356 and does not contain the digit D=3D=3 is 440000440000. So we should add 440000434356=5644440000−434356=5644.

Leave a Reply

Your email address will not be published. Required fields are marked *

*