W - Derangement Rotations
题号:NC224140
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

A Derangement is a permutation p of 1, 2, . . . , n where  for all i from 1 to n. A rotation of a sequence a_1, a_2, . . . , a_n 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.
示例1

输入

复制
3 1000000007

输出

复制
0
示例2

输入

复制
6 999999937

输出

复制
20