QOJ.ac

QOJ

Time Limit: 0.1 s Memory Limit: 64 MB Total points: 100

#13304. Fibonacci Representation

Statistics

The Fibonacci sequence is a sequence of integers, called Fibonacci numbers, defined as follows:

  • $\text{Fib}_{0}=0$, $\text{Fib}_{1}=1$, $\text{Fib}_{n}=\text{Fib}_{n-2}+\text{Fib}_{n-1}$ for $n > 1$

Its initial elements are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...

Byteasar investigates representations of numbers as sums or differences of Fibonacci numbers. Currently he is wondering what is the minimum representation, i.e., one with the minimum number of (not necessarily different) Fibonacci numbers, for a given positive integer $k$. For example, the numbers 10, 19, 17, and 1070 can be minimally represented using, respectively, 2, 2, 3, and 4 Fibonacci numbers as follows:

  • 10=5+5
  • 19=21-2
  • 17=13+5-1
  • 1070=987+89-5-1

Help Byteasar! Write a program that, for a given positive integer $k$ determines the minimum number of Fibonacci numbers required to represent $k$ as their sum or difference.

Input Format

In the first line of the standard input a single positive integer $p$ is given ($1 \le p \le 10$) that denotes the number of queries. The following $p$ lines hold a single positive integer $k$ each ($1 \le k \le 4\cdot 10^{17}$).

Output Format

For each query your program should print on the standard output the minimum number of Fibonacci numbers needed to represent the number $k$ as their sum or difference.

Example

Input

1
1070

Output

4

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.