A Derangement is a permutation p of 1, 2, . . . , n where
for all i from 1 to n. A rotation of a sequence
with offset
is equal to the sequence
. A sequence of length n has at most n distinct rotations. Given a derangement
, let
denote the number of distinct rotations of D that are also derangements. For example,
. Given n and a prime number p, count the number of derangements D of 1, 2, . . . , n such that
, modulo p.
输入描述:
The single line of input contains two integers
and
, where n is a permutation size, and p is a prime number.
输出描述:
Output a single integer, which is the number of derangements D of size n with
, modulo p.