Problems > Lucas Numbers Modulo

Lucas Numbers Modulo

Difficulty: 1700 4000 ms 128 MB

math matrix-exponentiation

The sequence obeys L(0)=2, L(1)=1 and L(n)=L(n−1)+L(n−2). Print f(N) modulo 109+7.

Input: one integer N.

Output: f(N) mod 109+7.

Constraints:

  • 0 ≤ N ≤ 1018

Sample Tests

Input 1
5
Output 1
11
Input 2
0
Output 2
2
Input 3
1
Output 3
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.