NBIN - New Binary

no tags 

One day Chandrima decided to make a list of all numbers starting from 1 in binary format, the list would be like 1, 10, 11, 100, ... and so on. Now she get bored of this list and decide to remove any pattern having at least two consecutive ones and prepare a new list. The new list will be like 1, 10, 100, 101, ... and so on. She then thought if a number n is given to her can she find the nth member of the new list. After trying for some time she comes to you for help. Can you help her by writing a program for her that coud do the specified task

Input

The first line contains T (<= 1000) test cases. The next T lines each contain one integer N (<= 10^15) for which you need to find the Nth member of the list.

Output

Output T lines each containing the required answer.

Example

Input:
3
1
2
3

Output:
1
10
100

hide comments
Petar Jesic: 2015-01-24 12:51:03

very interesting problem. Please note the output format.

Vamsi Krishna Avula: 2014-12-14 12:55:20

good question, took a while but just 13 lines of code ;)

Last edit: 2014-12-14 12:56:48
Pratham: 2014-06-30 20:53:42

my 100th.. :)

sobriquet: 2014-06-27 15:10:51

Take care of long long and int. By far the most interesting problem.

Ankit Paharia: 2014-06-02 10:07:22

very nice problem...

P_Quantum: 2014-05-31 08:55:15

nice one!!

kancha: 2014-05-14 07:00:54

nice problem :)

Last edit: 2014-05-14 07:10:43
sarelfeniel: 2014-05-08 07:49:56

Nice problem.

Gowtham Nagalingam: 2014-04-26 19:30:25

a good one

Kanish_The_Vista: 2014-04-25 10:45:31

@venky thanks


Added by:Abhra
Date:2014-04-16
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64