#P16870. [GKS 2022 #A] Challenge Nine

    ID: 19198 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>字符串贪心2022分类讨论Google Kick Start

[GKS 2022 #A] Challenge Nine

Problem Description

Ada gives John a positive integer NN. She challenges him to construct a new number (without leading zeros), that is a multiple of 99, by inserting exactly one digit (090 \ldots 9) anywhere in the given number NN. It is guaranteed that NN 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, TT. TT test cases follow.

Each test case has a single line containing a positive integer NN: the number Ada gives John.

Output Format

For each test case, output one line containing Case #x\#x: yy, where xx is the test case number (starting from 11) and yy is the new number constructed by John. As mentioned earlier, yy cannot have leading zeros.

3
5
33
12121
Case #1: 45
Case #2: 333
Case #3: 121212

Hint

In Sample Case #11, there are only 22 numbers that can be constructed satisfying the divisibility constraint: 4545 and 5454. John chooses the smaller number.

In Sample Case #22, 333333 is the only number possible.

In Sample Case #33, there are 44 possible options - 212121212121, 122121122121, 121221121221 and 121212121212 - out of which the smallest number is 121212121212.

Limits

1T1001 \le T \le 100.

Test Set 11

1N1051 \le N \le 10^5.

Test Set 22

For at most 1010 cases:

1N101234561 \le N \le 10^{123456}.

For the remaining cases:

1N1051 \le N \le 10^5.