Under construction

Still being built. Things may change

Kilometers to Miles

Time limit1sMemory limit128 MB

Summary
Convert each kilometer value to miles by writing it in Zeckendorf Fibonacci form, dropping the lowest bit, and re-evaluating.
Level

Easy3 of 10

Topics
Math, Greedy, Implementation, Number theory
Solved
No attempts yet

Problem

While preparing for a half marathon (about 21 km), Sang-geun first ran 21 miles, then learned that the race is 21 kilometers rather than 21 miles, which is about 13 miles. Both 21 and 13 are Fibonacci numbers! Inspired by this, he devised a way to convert kilometers to miles using a Fibonacci numeral system.

The Fibonacci numbers are defined as follows.

  • F1=1F_1 = 1
  • F2=2F_2 = 2
  • Fn+1=Fn+Fn−1F_{n+1} = F_n + F_{n-1} (n>1n > 1)

Every positive integer xx can be written as a sum of distinct Fibonacci numbers. That is, there always exist an integer kk and b1,b2,…,bkb_1, b_2, \ldots, b_k with bk=1b_k = 1 and bi∈{0,1}b_i \in \{0, 1\} (1≤i<k1 \le i < k) such that x=∑i=1kbi×Fix = \sum_{i=1}^{k} b_i \times F_i. We write this representation as b(x)=(bk,bk−1,…,b1)b(x) = (b_k, b_{k-1}, \ldots, b_1). To make the representation unique, we require bi×bi−1=0b_i \times b_{i-1} = 0 (i>1i > 1); that is, no two 1s appear consecutively.

For example, 21 is (1,0,0,0,0,0,0)(1, 0, 0, 0, 0, 0, 0) and 13 is (1,0,0,0,0,0)(1, 0, 0, 0, 0, 0).

The kilometer value xx is converted to the mile value yy as follows.

  1. Write xx in the Fibonacci numeral system as b(x)b(x).
  2. Shift b(x)b(x) one bit to the right, discarding the last bit. Call the result b(y)b(y).
  3. Compute the value represented by b(y)b(y); that value is yy.

For example, 42 is (1,0,0,1,0,0,0,0)(1, 0, 0, 1, 0, 0, 0, 0) in the Fibonacci system. Shifting it one bit to the right gives (1,0,0,1,0,0,0)(1, 0, 0, 1, 0, 0, 0), whose value is 0×1+0×2+0×3+1×5+0×8+0×13+1×21=260 \times 1 + 0 \times 2 + 0 \times 3 + 1 \times 5 + 0 \times 8 + 0 \times 13 + 1 \times 21 = 26.

Given kilometer values, write a program that converts each to miles using this algorithm.

Input

The first line contains the number of kilometer values to convert, tt. (0<t<250000 < t < 25000)

Each of the next tt lines contains one kilometer value xx to convert. (2<x<250002 < x < 25000)

Output

For each kilometer value xx, output the mile value yy obtained by the algorithm above, one per line.

Examples1

  1. Example 1

    Input
    5
    42
    100
    180
    300
    360
    
    Expected output
    26
    62
    111
    185
    222