Current location - Training Enrollment Network - Mathematics courses - Three solutions of Fibonacci queue algorithm
Three solutions of Fibonacci queue algorithm
Fibonacci series, also called golden section, was introduced by the mathematician Leonardoda Fibonacci, taking rabbit breeding as an example, so it is also called rabbit series, which refers to such a series: 0, 1, 1, 2, 3, 5, 8, 65444.

Mathematically, the recursive definition of Fibonacci sequence is as follows: F (0)=0, f (1) = 1, f (n) = f (n- 1)+f (n-2) (* n ≥ 2, n ≠.

result

abstract

Write a function, enter n, and find the nth term of Fibonacci sequence (that is, F(N)). Fibonacci sequence is defined as follows:

F(0) = 0,F( 1) = 1

F(N) = F(N- 1)+F(N-2), where N >;; 1.

Fibonacci series begins with 0 and 1, and the following Fibonacci numbers are obtained by adding the first two numbers.

The answer needs to be modulo 1e9+7 (100000007). If the initial result of calculation is: 100000008, please return to 1.

Example 1:

Input: n = 2

Output: 1

Example 2:

Input: n = 5

Output: 5

Tip:

0 & lt= n & lt= 100