Problems > Jacobsthal Numbers Modulo

Jacobsthal Numbers Modulo

Difficulty: 1700 4000 ms 128 MB

matrix-exponentiation

The Jacobsthal sequence is J(0)=0, J(1)=1, J(n)=J(n−1)+2J(n−2). Print J(N) modulo 109+7.

Input: one integer N.

Output: the value modulo 109+7.

Constraints:

  • 1 ≤ N ≤ 1018

Sample Tests

Input 1
4
Output 1
10
Input 2
1
Output 2
2
Input 3
1000000000000000000
Output 3
812984175

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.