Kilometers to Miles
Time limit1sMemory limit128 MB
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.
- ()
Every positive integer can be written as a sum of distinct Fibonacci numbers. That is, there always exist an integer and with and () such that . We write this representation as . To make the representation unique, we require (); that is, no two 1s appear consecutively.
For example, 21 is and 13 is .
The kilometer value is converted to the mile value as follows.
- Write in the Fibonacci numeral system as .
- Shift one bit to the right, discarding the last bit. Call the result .
- Compute the value represented by ; that value is .
For example, 42 is in the Fibonacci system. Shifting it one bit to the right gives , whose value is .
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, . ()
Each of the next lines contains one kilometer value to convert. ()
Output
For each kilometer value , output the mile value obtained by the algorithm above, one per line.