[Solved] Digit Removal codechef solution

October Challenge 2021 Division 3 (Rated) - CodeChef

Digit Removal codechef solution

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.

Digit Removal codechef solution

Input Format

  • 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.

Digit Removal codechef solution

Output Format

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

Digit Removal codechef solution


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

Digit Removal codechef solution


  • Subtask 1 (100 points): Original constraints

Sample Input 1 

21 5
8 8
100 0
5925 9
434356 3

Sample Output 1 



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.

Updating Soon…

Digit Removal codechef solution

Counting Tuples codechef solution


Leave a Comment