base and two digits first_digit and second_digit (they may be equal). Find the smallest integer that:
- is strictly greater than base;
- is divisible by base;
- is written using only the digits first_digit and second_digit (either one or both).
If no such number exists, or it is greater than 2³¹ - 1, return -1.base=6, first_digit=1, second_digit=2 → 12
Numbers made of 1 and 2 in increasing order: 1, 2, 11, 12, ... and 12 is above 6 and divisible by 6.
base=7, first_digit=7, second_digit=0 → 70
7 itself does not count, since the answer must be strictly greater. The next fit is 70.
base=4, first_digit=5, second_digit=5 → -1
Numbers made only of 5s are odd and never divisible by 4.
base=6, first_digit=1, second_digit=2
12
Run checks the first 3 tests in your browser. Submit checks all 118 tests on the server, hidden ones included.