#P16870. [GKS 2022 #A] Challenge Nine
[GKS 2022 #A] Challenge Nine
Problem Description
Ada gives John a positive integer . She challenges him to construct a new number (without leading zeros), that is a multiple of , by inserting exactly one digit () anywhere in the given number . It is guaranteed that does not have any leading zeros.
As John prefers smaller numbers, he wants to construct the smallest such number possible. Can you help John?
Input Format
The first line of the input gives the number of test cases, . test cases follow.
Each test case has a single line containing a positive integer : the number Ada gives John.
Output Format
For each test case, output one line containing Case : , where is the test case number (starting from ) and is the new number constructed by John. As mentioned earlier, cannot have leading zeros.
3
5
33
12121
Case #1: 45
Case #2: 333
Case #3: 121212
Hint
In Sample Case #, there are only numbers that can be constructed satisfying the divisibility constraint: and . John chooses the smaller number.
In Sample Case #, is the only number possible.
In Sample Case #, there are possible options - , , and - out of which the smallest number is .
Limits
.
Test Set
.
Test Set
For at most cases:
.
For the remaining cases:
.