#P13033. [GCJ 2021 #1C] Roaring Years

    ID: 12822 Type: RemoteJudge 30000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 5 Uploaded By: Tags>数学二分2021Google Code Jam

[GCJ 2021 #1C] Roaring Years

题目描述

Something is happening in 2021 that has not happened in over a century. 2021, like 1920 before it, is a roaring year. A year represented by a positive integer yy is roaring if the decimal writing (without leading zeroes) of yy is the concatenation of the decimal writing (without leading zeroes) of two or more distinct consecutive positive integers, in increasing order. In this case, 2021 is a roaring year because it is the concatenation of 20 and 21.

Other examples of roaring years are 12, 789, 910, 1234, and 9899100. 2020 was not roaring because the only list of two or more positive integers that concatenate into 2020 is [20,20][20, 20], and it is not made of consecutive integers. Similarly, there are only three lists for 2019: [20,1,9][20, 1, 9], [201,9][201, 9], and [20,19][20, 19]. The first two are not made of consecutive integers, while the third does not have the integers in increasing order. Thus, 2019 was also not roaring. As a final example, 778 was not a roaring year because [7,78][7, 78] and [77,8][77, 8] are not made up of consecutive integers and [7,7,8][7, 7, 8] is not made up of distinct integers.

Given the current year (which may or may not be roaring), find what the next roaring year is going to be.

输入格式

The first line of the input gives the number of test cases, T\textbf{T}. T\textbf{T} lines follow. Each line represents a test case and contains a single integer Y\textbf{Y}, the current year.

输出格式

For each test case, output one line containing Case #x: z, where xx is the test case number (starting from 1) and zz is the first year strictly after Y\textbf{Y} that is roaring.

4
2020
2021
68000
101
Case #1: 2021
Case #2: 2122
Case #3: 78910
Case #4: 123

提示

Sample Explanation

Notice in the last Sample Case that 102 is not a roaring year because [10,2][10, 2] is not a list of consecutive integers and you cannot write 2 with a leading zero to use [1,02][1, 02].

Limits

  • 1T1001 \leq \textbf{T} \leq 100.

Test Set 1 (15 Pts, Visible Verdict)

  • 1Y1061 \leq \textbf{Y} \leq 10^6.

Test Set 2 (20 Pts, Hidden Verdict)

  • 1Y10181 \leq \textbf{Y} \leq 10^{18}.