Fibonacci Number 7
InterviewTime limit1sMemory limit512 MB
Compute the n-th Fibonacci number modulo 1,000,000,007 for n up to one million.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Math, Implementation
- Solved
- No attempts yet
Problem
The Fibonacci sequence starts with 0 and 1. The 0th Fibonacci number is 0 and the 1st Fibonacci number is 1. From the 2nd number on, each Fibonacci number is the sum of the two numbers directly before it.
As a formula, ().
The Fibonacci numbers up to are:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597
Given , write a program that finds the -th Fibonacci number.
Input
The first line contains . is 0 or a natural number at most 1,000,000.
Output
Print the -th Fibonacci number modulo 1,000,000,007 on the first line.