#P13159. [GCJ 2017 Qualification] Tidy Numbers

[GCJ 2017 Qualification] Tidy Numbers

题目描述

Tatiana likes to keep things tidy. Her toys are sorted from smallest to largest, her pencils are sorted from shortest to longest and her computers from oldest to newest. One day, when practicing her counting skills, she noticed that some integers, when written in base 10 with no leading zeroes, have their digits sorted in non-decreasing order. Some examples of this are 8, 123, 555, and 224488. She decided to call these numbers tidytidy. Numbers that do not have this property, like 20, 321, 495 and 999990, are not tidy.

She just finished counting all positive integers in ascending order from 1 to NN. What was the last tidy number she counted?

输入格式

The first line of the input gives the number of test cases, TT. TT lines follow. Each line describes a test case with a single integer NN, the last number counted by Tatiana.

输出格式

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the last tidy number counted by Tatiana.

4
132
1000
7
111111111111111110
Case #1: 129
Case #2: 999
Case #3: 7
Case #4: 99999999999999999

提示

Sample Explanation

Note that the last sample case would not appear in the Small dataset.

Limits

  • 1T1001 \leq T \leq 100.

Small dataset (5 Pts, Test Set 1 - Visible)

  • 1N10001 \leq N \leq 1000.

Large dataset (10 Pts, Test Set 2 - Hidden)

  • 1N10181 \leq N \leq 10^{18}.