#P10744. [SEERC 2020] Modulo Permutations

[SEERC 2020] Modulo Permutations

Problem Description

Count the number of all permutations of 1n1 \sim n of length nn that satisfy pimodpi+12p_i \bmod p_{i+1} \leq 2 (where pn+1=p1p_{n+1} = p_1), and output the result modulo 109+710^9 + 7.

Input Format

One integer n (1n106)n\ (1 \leq n \leq 10^6).

Output Format

Output the answer modulo 109+710^9+7.

1
1
2
2
3
6
4
16
5
40
1000000
581177467

Hint

Translated by ChatGPT 5