Logo
(追記) (追記ここまで)

8229번 - Fibonacci Representation 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 128 MB107654867.606%

문제

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

  • Fib0=0, Fib1=1, Fibn=Fibn-2+Fibn-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.

입력

In the first line of the standard input a single positive integer p is given (1 ≤ p ≤ 10) that denotes the number of queries. The following p lines hold a single positive integer k each (1 ≤ k ≤ 4⋅1017).

출력

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.

제한

예제 입력 1

1
1070

예제 출력 1

4

힌트

출처

Olympiad > Polish Olympiad in Informatics > POI 2011/2012 > Stage 2 5번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /