PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000363. Bài tập của đàn bò (Exercise)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Bài tập của đàn bò (Exercise)

Exercise

Source: USACO

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN cows, labeled 11 through NN. Consider a permutation PP of these labels. Apply the same permutation simultaneously to all positions, repeatedly, until the original order is restored.

The least positive number of applications is the order of the permutation. If its disjoint cycle lengths are c1,c2,…,crc_1,c_2,\ldots,c_r, the order is lcm⁡(c1,…,cr)\operatorname{lcm}(c_1,\ldots,c_r).

Consider the set of distinct attainable permutation orders for permutations of NN elements. Compute the sum of those distinct positive integers modulo the prime MM. Different permutations with the same order contribute only once.

Input

One line with integers N,MN,M. MM is prime.

Output

A single integer, the sum modulo MM. The PHOJ version uses standard input/output instead of USACO's exercise.in and exercise.out files.

Subtasks

  • Subtask 1 (20 points): 1<=N<=9;108<=M<=109+7;Misprime1 <= N <= 9; 10^8 <= M <= 10^9+7; M is prime.
  • Subtask 2 (30 points): 1<=N<=200;108<=M<=109+7;Misprime1 <= N <= 200; 10^8 <= M <= 10^9+7; M is prime.
  • Subtask 3 (50 points): 1<=N<=10000;108<=M<=109+7;Misprime1 <= N <= 10000; 10^8 <= M <= 10^9+7; M is prime.

Examples

Example 1

Input

5 1000000007

Output

21

Explanation

For N=5 the distinct possible return periods are 1,2,3,4,5,6. Their sum is 21.

Example 2

Input

1 998244353

Output

1

Explanation

A permutation of one element only contains a fixed point, so its order is 1.