Sum of Squares of Fibonacci Numbers
Time limit1sMemory limit256 MB
Read n up to 1e18 and print the sum of squared Fibonacci numbers F_0 through F_n modulo 1,000,000,007.
- Level
Medium6 of 10
- Topics
- Math, Matrix, Divide and conquer
- Solved
- No attempts yet
Problem
The Fibonacci numbers start with 0 and 1. The 0th Fibonacci number is 0, the 1st is 1, and from the 2nd on each one is the sum of the two before it. As a formula, for .
Written out up to , the Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597.
Given , write a program that adds up the squares of the Fibonacci numbers from the 0th through the th.
Input
The first line contains . It is a natural number between 1 and 1,000,000,000,000,000,000, inclusive.
Output
Print modulo 1,000,000,007 on the first line.