#ddcc2020qualf. [ddcc2020_qual_f]DISCOSMOS
[ddcc2020_qual_f]DISCOSMOS
Problem Statement
In , DISCO creates a new universe called DISCOSMOS to celebrate its -th anniversary.
DISCOSMOS can be described as an grid. Let denote the square at the -th row from the top and the -th column from the left.
At time , one robot will be placed onto each square. Each robot is one of the following three types:
- Type-H: Does not move at all.
- Type-R: If a robot of this type is in at time , it will be in at time . If it is in at time , however, it will be instead in at time . (The robots do not collide with each other.)
- Type-D: If a robot of this type is in at time , it will be in at time . If it is in at time , however, it will be instead in at time .
There are possible ways to place these robots. In how many of them will every square be occupied by one robot at times , and all subsequent multiples of ?
Since the count can be enormous, compute it modulo .
Constraints
- are all integers.
Input
Input is given from Standard Input in the following format:
Output
Print the number of ways to place the robots that satisfy the condition, modulo .
Sample Input 1
2 2 1
Sample Output 1
9
Shown below are some of the ways to place the robots that satisfy the condition, where .
, >
, and v
stand for Type-H, Type-R, and Type-D, respectively:
>> .. vv
.. .. vv
Sample Input 2
869 120 1001
Sample Output 2
672919729