QOJ.ac

QOJ

Time Limit: 2 s - 4 s Memory Limit: 1024 MB Total points: 35

#5795. The Next Number

统计

Problem

You are writing out a list of numbers. Your list contains all numbers with exactly Di digits in its decimal representation which are equal to i, for each i between 1 and 9, inclusive. You are writing them out in ascending order.

For example, you might be writing every number with two '1's and one '5'. Your list would begin 115, 151, 511, 1015, 1051.

Given N, the last number you wrote, compute what the next number in the list will be.

Input

The first line of input contains an integer T, the number of test cases in the input. T lines follow, one for each test case, each containing a single integer N.

Output

For each test case, output

Case #X: K
where X is the test case number, starting from 1, and K is the next integer in the list.

Limits

Memory limit: 1 GB.

Small dataset (9 Points)

Time limit: 20 2 seconds.

1 ≤ T ≤ 50

1 ≤ N ≤ 106

Large dataset (26 Points)

Time limit: 30 4 seconds.

1 ≤ T ≤ 500

1 ≤ N ≤ 1020

Sample

3
115
1051
6233
Case #1: 151
Case #2: 1105
Case #3: 6323
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.