Problems
10111 - N'th Lucky Number
SUBMIT PROBLEM

N'th Lucky Number

Time Limit: 1 sec

 

The Problem

Lucky numbers consist of exactly those positive integers which are powers of 7 (such as 70 = 1 and 73 = 343) and those that are a sum of unique powers of 7 (such as 50 = 70 + 72 or 56 = 71 + 72, but not 14 = 71 + 71). The sequence

 

1, 7, 8, 49, 50, 56, 57, 343, 344, 350

 

shows the first 10 lucky numbers.

 

Given an integer number N, you need to find the Nth lucky number.

 

The Input

The first line contains an integer number T, which indicates the number of test cases (0<T<10000). Each test case is given in one line. This line contains a positive integer number N (0<N<60000).

 

The Output

For each test case, print a single line “Case X: L”, here X is the case number start from 1 to T and L is the Nth lucky number.

 

Sample Input

3

1

4

6

 

Sample Output

Case 1: 1

Case 2: 49

Case 3: 56

 

 

 

[School & College Level]

Inter School & College Programming Contest (ISCPC) 2017

Problem Setter: Shahin ShamS