In the Counting Poetry Slam, a performer takes the microphone, chooses a number N, and counts aloud from 1 to N.
That is, she starts by saying 1, and then repeatedly says the number
that is 1 greater than the previous number she said, stopping after she
has said N.
It's your turn to perform, but you find this process tedious, and you
want to add a twist to speed it up: sometimes, instead of adding 1 to
the previous number, you might reverse the digits of the number
(removing any leading zeroes that this creates). For example, after
saying "16", you could next say either "17" or "61"; after saying
"2300", you could next say either "2301" or "32". You may reverse as
many times as you want (or not at all) within a performance.
The first number you say must be 1; what is the fewest number of numbers you will need to say in order to reach the number N? 1 and N count toward this total. If you say the same number multiple times, each of those times counts separately.
The first line of the input gives the number of test cases, T. T lines follow. Each has one integer N, the number you must reach.
For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the minimum number of numbers you need to say.
1 ≤ T ≤ 100.
1 ≤ N ≤ 10^{6}.
1 ≤ N ≤ 10^{14}.
Input |
Output |
3 1 19 23 |
Case #1: 1 Case #2: 19 Case #3: 15 |
Points | Correct | Attempted |
---|---|---|
11pt | 3091 | 5308 |
14pt | 955 | 1400 |