Tikal
Time limit2sMemory limit1024 MB
Count the distinct ways to place k identical figurines on the n sides of a regular n-gon, treating rotations as the same, modulo prime p.
- Level
Medium6 of 10
- Topics
- Combinatorics, Number theory
- Solved
- No attempts yet
Problem
The Maya built a beautiful temple in the city of Tikal. The temple is a regular -gon whose sides are indistinguishable. By tradition, identical idol figurines were placed inside the temple. The shamans insist that the figurines must stand by the walls of the temple, meaning the sides of the -gon. Different walls may hold different numbers of figurines. Following custom, the Chief Shaman must rearrange the figurines into a new configuration every morning.
After the temple was built, spirits appeared and warned that once a configuration of figurines repeats, the sky will fall, the seas will overflow, and the world will end. They also clarified that configurations obtained by rotating the temple are considered the same.
The Chief Shaman asks how many distinct configurations of the figurines exist in the temple. Since this number can be very large, he wants the answer modulo the prime .
Input
The first line contains three integers , , and (; ; ). It is guaranteed that is prime.
Output
Print a single integer: the number of distinct arrangements of idols among the walls of the temple, counting configurations equal under rotation as one, modulo .
Hint
In the second test case, the possible arrangements are:
(,,,,,) (,,,,,) (,,,,,) (,,,,,) (,,,,,)
(,,,,,) (,,,,,) (,,,,,) (,,,,,) (,,,,,)