QOJ.ac

QOJ

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

#13304. Fibonacci Representation

统计

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
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.