#P6280. [USACO20OPEN] Exercise G

    ID: 7078 远端评测题 2000ms 250MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP2020USACO素数判断,质数,筛法

[USACO20OPEN] Exercise G

Problem Description

Farmer John has (again) come up with a new morning exercise plan for his cows.
As before, Farmer John’s NN cows stand in a line. For each ii with 1iN1 \le i \le N, the ii-th cow from left to right has ID ii. He tells them to repeat the following step until the cows return to the same order as they started.

Given a permutation AA of length NN, the cows change their order so that the cow that was ii-th from left to right before the change becomes the AiA_i-th from left to right after the change.
For example, if A=(1,2,3,4,5)A = (1,2,3,4,5), then the cows perform a total of one step. If A=(2,3,1,5,4)A = (2,3,1,5,4), then the cows perform a total of six steps. After each step, the order of the cows from left to right is as follows:

00 steps: (1,2,3,4,5)(1,2,3,4,5)
11 step: (3,1,2,5,4)(3,1,2,5,4)
22 steps: (2,3,1,4,5)(2,3,1,4,5)
33 steps: (1,2,3,5,4)(1,2,3,5,4)
44 steps: (3,1,2,4,5)(3,1,2,4,5)
55 steps: (2,3,1,5,4)(2,3,1,5,4)
66 steps: (1,2,3,4,5)(1,2,3,4,5)

Find the sum of all positive integers KK such that there exists a permutation of length NN for which the cows need exactly KK steps.

Since this number may be very large, output the remainder of the answer modulo MM (108M109+710^8 \le M \le 10^9 + 7, and MM is prime).

Input Format

The first line of input contains NN and MM.

Output Format

Output one integer.

5 1000000007
21

Hint

Sample Explanation:

There exist permutations such that the cows need 11, 22, 33, 44, 55, and 66 steps. Therefore, the answer is 1+2+3+4+5+6=211 + 2 + 3 + 4 + 5 + 6 = 21.


For 100%100\% of the testdata, 1N1041 \le N \le 10^4.

There are 1010 test points. Test point 11 is the sample, and the rest have the following properties:

Test points 22 to 55 satisfy N102N \le 10^2.
Test points 66 to 1010 have no additional constraints.


Problem setter: Benjamin Qi

Translated by ChatGPT 5