#P6280. [USACO20OPEN] Exercise G
[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 cows stand in a line. For each with , the -th cow from left to right has ID . He tells them to repeat the following step until the cows return to the same order as they started.
Given a permutation of length , the cows change their order so that the cow that was -th from left to right before the change becomes the -th from left to right after the change.
For example, if , then the cows perform a total of one step. If , then the cows perform a total of six steps. After each step, the order of the cows from left to right is as follows:
steps:
step:
steps:
steps:
steps:
steps:
steps:
Find the sum of all positive integers such that there exists a permutation of length for which the cows need exactly steps.
Since this number may be very large, output the remainder of the answer modulo (, and is prime).
Input Format
The first line of input contains and .
Output Format
Output one integer.
5 1000000007
21
Hint
Sample Explanation:
There exist permutations such that the cows need , , , , , and steps. Therefore, the answer is .
For of the testdata, .
There are test points. Test point is the sample, and the rest have the following properties:
Test points to satisfy .
Test points to have no additional constraints.
Problem setter: Benjamin Qi
Translated by ChatGPT 5