Fibonacci Number
InterviewTime limit1sMemory limit128 MB
Given n, print the n-th Fibonacci number, where the sequence starts 1, 1 and each later term is the sum of the previous two.
- Level
Easy3 of 10
- Topics
- Dynamic programming, Math, Implementation, Recursion
- Solved
- No attempts yet
Problem
The Fibonacci sequence is built by adding the previous two terms to obtain the next one. Its first two terms are both 1.
Given an integer , write a program that prints the -th Fibonacci number .
Input
The first line contains an integer . The input is always chosen so that has at most 1000 digits.
Output
Print the -th Fibonacci number on the first line.
Hint
Every answer in this problem has at most 1000 digits. For example, , which has 4 digits.