Algorithm


Problem link- https://www.spoj.com/problems/TSHOW1/

TSHOW1 - Amusing numbers

 

Amusing numbers are numbers consisting only of digits 5 and 6. Given an integer k , display the k-th amusing number.

Input

FIrst line consists of integer N representing number of test cases

Next N lines consist of N integers (1 <= k <= 10^15)

Output

N lines each displaying corresponding k-th amusing number

Example

Input:
2
1
5

Output:
5
65

 

Code Examples

#1 Code Example with Python Programming

Code - Python Programming

T = int(input())
for _ in range(T):
    N = int(input())
    level = 1
    while N > (1 << level):
        N -= (1 << level)
        level += 1
    result = ""
    N -= 1
    for i in range(level):
        if N % 2 == 0:
            result += '5'
        else:
            result += '6'
        N //= 2
    print(result[::-1])
Copy The Code & Try With Live Editor

Input

x
+
cmd
2
1
5

Output

x
+
cmd
5
65
Advertisements

Demonstration


SPOJ Solution-Amusing numbers-Solution in C, C++, Java, Python

Previous
SPOJ Solution - Test Life, the Universe, and Everything - Solution in C, C++, Java, Python