Derangement Rotations

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

A Derangement is a permutation pp of 1,2,,n1, 2, \dots , n where p_iip\_i \ne i for all ii from 11 to nn.

A rotation of a sequence a_1,a_2, ,a_na\_1, a\_2, \dots , a\_n with offset kk (1kn1 \le k \le n) is equal to the sequence a_k,a_k+1,,a_n,a_1,a_2,,a_k1a\_k, a\_{k+1}, \dots, a\_n, a\_1, a\_2, \dots, a\_{k-1}. A sequence of length nn has at most nn distinct rotations.

Given a derangement DD, let f(D)f(D) denote the number of distinct rotations of DD that are also derangements. For example, f(\[2,1])=1f(\[2, 1]) = 1, f(\[3,1,2])=2f(\[3, 1, 2]) = 2.

Given nn and a prime number pp, count the number of derangements DD of 1,2,,n1, 2, \dots , n such that f(D)=n2f(D) = n - 2, modulo pp.

입력

The single line of input contains two integers nn (3n1063 \le n \le 10^6) and pp (108p109+710^8 \le p \le 10^9 + 7), where nn is a permutation size, and pp is a prime number.

출력

Output a single integer, which is the number of derangements DD of size nn with f(D)=n2f(D) = n - 2, modulo pp.