#204. 斐波那契数列的递归实现

    ID: 204 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatWarmup-2gesp5递归数学基础

斐波那契数列的递归实现

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 00 and 11 (essentially 22 base cases). Each subsequent value is the sum of the previous two values, so the whole sequence is: 0,1,1,2,3,5,8,13,210, 1, 1, 2, 3, 5, 8, 13, 21 and so on. Define a recursive fibonacci(n) method that returns the nn-th Fibonacci number, with n=0n=0 representing the start of the sequence.

Input Format

The input is given from standard input in the following format.

nn

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 n=0n=0, the 00-th Fibonacci number is 00. For Sample 2, when n=1n=1, the 11-st Fibonacci number is 11. For Sample 3, when n=2n=2, the 22-nd Fibonacci number is F2=F1+F0=1+0=1F_2 = F_1 + F_0 = 1 + 0 = 1.

Constraints

Time limit: 11 second, Memory limit: 10241024 KiB for each test case.