Cow Exercise
Time limit1sMemory limit512 MB
Given N and prime M, sum every positive integer K for which some permutation of length N has order K, then output the sum modulo M.
- Level
Hard9 of 10
- Topics
- Math, Number theory, Combinatorics, Dynamic programming
- Solved
- No attempts yet
Problem
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
The first line contains and .
Output
A single integer.
Notes
There exist permutations that cause the cows to take , , , , , and steps. Thus, the answer is .