Base or Bias Codechef solutions Today | Codechef Starters 72 ✅ (100/100) FULL | AC Code ✅| RJBIAS
Problem
Reyaan has given you the following problem to solve:
You are given an integer in base , represented by an array of length such that
- for every
Note that in this problem.
Find the smallest non-negative integer such that contains every digit from to in its base- representation.
can be very large, so print the answer modulo .
Note: Leading zeros are not counted as part of the number, so for example has only two distinct digits: and . However, does have three distinct digits.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains two space-separated integers and — the size of the array and the base.
- The second line of each test case contains space-separated integers .
Output Format
For each test case, output on a new line the value of , modulo .
Constraints
- , i.e, the given number doesn't contain leading zeros.
- The sum of across all test cases won't exceed .
Sample 1:
4 4 4 3 1 0 2 4 5 1 2 3 4 2 2 1 1 1 3 2
0 500 1 9
Explanation:
Test case : All the digits from to are already present in the given array, so .
Test case : In base , represents the integer . The smallest number larger than the given one that contains every digit is , which represents . The difference between them is .
Test case : We have , which is in binary. If we add to it, we obtain , which is in binary and has both digits.