#abc300e. E - Dice Product 3
E - Dice Product 3
Score : points
问题陈述
你有一个整数 和一枚骰子,骰子掷出的整数在 到 (包括两端点)之间,并且每个整数出现的概率相等。
当你手中的整数严格小于 时,重复执行以下操作:
- 投掷骰子。若骰子显示数字 ,则将你的整数乘以 。
求当你的整数最终变为 时的概率,该概率对 取模。
如何计算模 下的概率?我们能够证明所求概率总是有理数。另外,在本题约束条件下,当该概率表示为两个互质整数 和 的形式 时,我们可以证明存在一个唯一的整数 ,满足 以及 。找出这个 。
以上为通义千问 qwen-max 翻译,仅供参考。
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
update @ 2024/3/10 08:24:38