-->
当前位置:首页 > 题库

PROGRAMMING:Is he a member of the Fibonacci family?

Luz5年前 (2021-05-10)题库405
Mathematically, Fibonacci sequence is defined recursively as follows:
F(0)=0,F(1)=1, F(n)=F(n-1)+F(n-2)(n>=2,n∈N*)
This sequence has a very important aesthetic characteristic: when n tends to infinity, the ratio of the former term to the latter term is more and more close to the golden section, that is, f (n) / F (n-1) → 1.618..., that is, the ratio of the former term to the latter term
![ 20200321152054_ 43493.jpg](~/9e8c7d1d-906a-44e4-8f4e-9f1ae478bf48.jpg)
The formation of nature is closely related to this aesthetics
![ 20200321151837_ 79195.jpg](~/7d9b5d89-a31a-4d48-af55-6b7e79fc2821.jpg)
After understanding this sequence, you need to be more familiar with Fibonacci sequence through programming
Given a positive integer n (n > 1), output the number of terms in the Fibonacci sequence. If it does not exist in the sequence, output - 1. Here we stipulate that the first term of the sequence is f (1) = 1, the second term f (2) = 1.
Note: it is suggested to use functions for modular programming
```
Void generate() / / generate Fibonacci sequence
{
}
Bool judge (int x) / / judge whether a number x is in the sequence
{
}
Int main() / / main function
{
return 0;
}
```
###Input format:
One line, positive integer n, (1 < n < = 1000000)
###Output format:
If n is not in the sequence, output - 1
###Input example:
Sample input 1:
```in
two
```
Sample input 2:
```in
eight
```
###Output example:
Sample output 1:
```out
three
```
Sample output 2:
```out
six
```







answer:If there is no answer, please comment