#5193. Problem 3. Exercise
Problem 3. Exercise
Problem 3. Exercise
USACO 2020 US Open Contest, Gold
Farmer John has come up with a new morning exercise routine for the cows (again)!
As before, Farmer John's cows () are standing in a line. The -th cow from the left has label for each . He tells them to repeat the following step until the cows are in the same order as when they started.
- Given a permutation of length , the cows change their order such that the -th cow from the left before the change is -th from the left after the change.
For example, if then the cows perform one step. If , then the cows perform six steps. The order of the cows from left to right after each step is as follows:
- 0 steps:
- 1 step:
- 2 steps:
- 3 steps:
- 4 steps:
- 5 steps:
- 6 steps:
Find the sum of all positive integers such that there exists a permutation of length that requires the cows to take exactly steps.
As this number may be very large, output the answer modulo (, is prime).
INPUT FORMAT (file exercise.in):
The first line contains and .
OUTPUT FORMAT (file exercise.out):
A single integer.
SAMPLE INPUT:
5 1000000007
SAMPLE OUTPUT:
21
There exist permutations that cause the cows to take , , , , , and steps. Thus, the answer is .
SCORING: Test cases 2-5 satisfy .Test cases 6-10 satisfy no additional constraints.
Problem credits: Benjamin Qi