#204. 斐波那契数列的递归实现
斐波那契数列的递归实现
Fibonacci Sequence
Background
In the world of mathematics, the Fibonacci sequence is a very famous series. It is known for its unique recursive definition and has wide applications in nature and computer science.
Problem Description
The Fibonacci sequence is a famous bit of mathematics, and it happens to have a recursive definition. The first two values in the sequence are and (essentially base cases). Each subsequent value is the sum of the previous two values, so the whole sequence is: and so on. Define a recursive fibonacci(n) method that returns the -th Fibonacci number, with representing the start of the sequence.
Input Format
The input is given from standard input in the following format.
Output Format
Output to standard output in the following format.
Fibonacci number
Sample
0
0
1
1
2
1
Sample Explanation
For Sample 1, when , the -th Fibonacci number is . For Sample 2, when , the -st Fibonacci number is . For Sample 3, when , the -nd Fibonacci number is .
Constraints
Time limit: second, Memory limit: KiB for each test case.