Particles
Time limit5sMemory limit64 MB
Count functions from N chambers to themselves such that applying the function K times returns every element to its start, modulo M.
- Level
Hard8 of 10
- Topics
- Combinatorics, Dynamic programming, Number theory
- Solved
- No attempts yet
Problem
Mirko was hired as a physicist at the European Organization for Nuclear Research (CERN), and his first assignment is to draw the blueprint of the newest particle accelerator.
The accelerator has exactly chambers, and at the moment an experiment starts every chamber holds one particle. Each chamber has exactly one chamber that follows it. Every second, all particles move at the same time from the chamber they are in to the chamber that follows it. If chamber follows chamber , chamber does not have to follow chamber , although two chambers may follow each other.
The condition that matters most for the experiment is that after seconds every particle is back in the chamber it started in. Mirko wants to know how many blueprints satisfy this condition. Two blueprints are different when some chamber is followed by a different chamber in each of them. The number of blueprints can be very large, so report only its remainder after division by .
Note that a chamber may follow itself.
Input
The first line contains two numbers and separated by a space (). is the total number of chambers Mirko has for building the accelerator, and is the time in seconds after which every particle must be back in its starting chamber.
The second line contains the modulus ().
Output
Print on the first line the number of different blueprints that satisfy the condition, modulo .