#P16870. [GKS 2022 #A] Challenge Nine

    ID: 17116 Type: RemoteJudge 2000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 3 Uploaded By: Tags>字符串贪心2022分类讨论Google Kick Start

[GKS 2022 #A] Challenge Nine

题目描述

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 (0…90 \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?

输入格式

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.

输出格式

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

提示

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

1≤T≤1001 \le T \le 100.

Test Set 11

1≤N≤1051 \le N \le 10^5.

Test Set 22

For at most 1010 cases:

1≤N≤101234561 \le N \le 10^{123456}.

For the remaining cases:

1≤N≤1051 \le N \le 10^5.