MAIN12A - SelfDescribingSequenceProblem

no tags 

Everyone loves Swampy. Swampy the Alligator lives under the city and yearns for a more human like existence. Swampy recently learned a new self describing sequence. The sequence is described in blocks where each block has the same number and two consecutive blocks have consecutive numbers in them. To construct the sequence start with '1'. Now '1' means that the following block is of length 1. As '1' was chosen in previous block, therefore '2' is chosen for the current block making the sequence '12'. Now '2' means that the following block is of length 2. As '2' was chosen in previous block, therefore '3' is chosen for the current block making the sequence '1233'. Now '33' means that the following 2 blocks are of length 3. As '3' was chosen in previous block, therefore '4' is chosen for the current block making the sequence '1233444'. And the second '3' in the sequence appends '555' in the already generated sequence, making the sequence '1233444555'.

Input

First line of the input contains an integer T, the number of test cases. Then T test cases follow. Each test case consists of a single integer N.

Output

For each test case, print Case #X: S, where X is the test case number starting from 1, S is the Nth term of the sequence described above.

Example

Input:
4
1
2
3
4

Output:
Case #1: 1
Case #2: 2
Case #3: 3
Case #4: 3

Constraints: T <= 10000 1 <= N <= 1000000


hide comments
Goldie: 2012-04-23 12:11:55

@Nikunj ..... plz tell me whts wrong with my code... working for all my random TCs.... still getting WA... 6893497

Aradhya: 2012-04-11 16:26:41

swampy ki maa ka

well i am lagging: 2012-03-30 02:35:19

AC :)

Last edit: 2012-03-31 04:54:24
Alex Anderson: 2012-03-28 21:12:21

Don't think of it as one big string. It is a sequence, where you are grouping some elements together as "blocks".

Pranay: 2012-03-28 02:42:31

would 444 mean the next 3 blocks (including the 555 block) would be of lenght 4 each ?

mehmetin: 2012-03-26 09:25:08

@gupta: I solved it, the output can be 2 or 3 or more digit numbers. It shouldn't be taken as digits or characters in the resulting string.

Sidharth Gupta: 2012-03-25 20:02:13

are you talking about "numbers" or "digits" in blocks?? as in what happens when 2-digit or 3-digit numbers start appearing.. should they be considered as each digit of the number in a single block and then apply the rule or the other way round??

mehmetin: 2012-03-25 13:38:00

Are we supposed to print a number or one single digit of the sequence?


Added by:Nikunj Jain
Date:2012-03-15
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Vaibhav Mittal