#abc300e. [abc300_e]Dice Product 3
[abc300_e]Dice Product 3
Problem Statement
You have an integer and a die that shows integers between and (inclusive) with equal probability.
You repeat the following operation while your integer is strictly less than :
- Cast a die. If it shows , multiply your integer by .
Find the probability, modulo , that your integer ends up being .
How to find a probability modulo ? We can prove that the sought probability is always rational. Additionally, under the constraints of this problem, when that value is represented as with two coprime integers and , we can prove that there is a unique integer such that and . Find this .
Constraints
- is an integer.
Input
The input is given from Standard Input in the following format:
Output
Print the probability, modulo , that your integer ends up being .
Sample Input 1
6
Sample Output 1
239578645
One of the possible procedures is as follows.
- Initially, your integer is .
- You cast a die, and it shows . Your integer becomes .
- You cast a die, and it shows . Your integer becomes .
- Now your integer is not less than , so you terminate the procedure.
Your integer ends up being , which is not equal to .
The probability that your integer ends up being is . Since , print .
Sample Input 2
7
Sample Output 2
0
No matter what the die shows, your integer never ends up being .
Sample Input 3
300
Sample Output 3
183676961
Sample Input 4
979552051200000000
Sample Output 4
812376310