Count the number of all permutations of 1∼n of length n that satisfy pimodpi+1≤2 (where pn+1=p1), and output the result modulo 109+7.
One integer n (1≤n≤106).
Output the answer modulo 109+7.
1
1
2
2
3
6
4
16
5
40
1000000
581177467
Translated by ChatGPT 5