Under construction

Still being built. Things may change

Determinants and GCD

Time limit2sMemory limit512 MB

Summary
For a tridiagonal matrix with a fixed pattern, let D(k) be its k-by-k determinant and compute the sum of gcd(D(i), D(N)) for i from 1 to N, modulo 1e9+7.
Level

Hard8 of 10

Topics
Math, Number theory, Dynamic programming, Combinatorics
Solved
No attempts yet

Problem

The entries of the N×NN \times N matrix MM are as follows.

  • M(i,i)=1M(i, i) = 1
  • M(i,i+1)=1M(i, i+1) = 1
  • M(i,i−1)=−1M(i, i-1) = -1
  • every other entry is 0

For example, when N=4N = 4, MM is

1 1 0 0
-1 1 1 0
0 -1 1 1
0 0 -1 1

Let D(k)D(k) be the determinant of the k×kk \times k matrix built by the same rule. Given NN, write a program that computes S=∑i=1Ngcd⁡(D(i),D(N))S = \sum_{i=1}^{N} \gcd(D(i), D(N)).

Input

The first line contains NN. (1≤N≤1000001 \le N \le 100000)

Output

Print SS modulo 109+710^9+7. The gcd⁡\gcd is computed from the actual determinant values, before any reduction modulo 109+710^9+7.

Examples5

  1. Example 1

    Input
    1
    
    Expected output
    1
    
  2. Example 2

    Input
    2
    
    Expected output
    3
    
  3. Example 3

    Input
    3
    
    Expected output
    5
    
  4. Example 4

    Input
    4
    
    Expected output
    8
    
  5. Example 5

    Input
    5
    
    Expected output
    13