#abc263e. E - Sugoroku 3
E - Sugoroku 3
Score : points
问题陈述
有 个正方形,分别称为第 1 个正方形到第 个正方形。你从第 1 个正方形开始。
从第 1 个正方形到第 个正方形上的每个正方形都有一颗骰子。在第 个正方形上的骰子标记着从 到 的整数,且每个数字出现的概率相等。(各骰子的滚动是相互独立的。)
直到你到达第 个正方形之前,你需要重复在当前所在的正方形上投掷骰子。这里的规则是:如果在第 个正方形上投掷骰子得到整数 ,则你将移动到第 个正方形。
求模 后,投掷骰子次数的期望值。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There are squares called Square though Square . You start on Square .
Each of the squares from Square through Square has a die on it. The die on Square is labeled with the integers from through , each occurring with equal probability. (Die rolls are independent of each other.)
Until you reach Square , you will repeat rolling a die on the square you are on. Here, if the die on Square rolls the integer , you go to Square .
Find the expected value, modulo , of the number of times you roll a die.
Notes
It can be proved that the sought expected value is always a rational number. Additionally, if that value is represented using two coprime integers and , there is a unique integer such that and . Find this .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
1 1
Sample Output 1
4
The sought expected value is , so should be printed.
Here is one possible scenario until reaching Square :
- Roll on Square , and go to Square .
- Roll on Square , and stay there.
- Roll on Square , and go to Square .
This scenario occurs with probability .
Sample Input 2
5
3 1 2 1
Sample Output 2
332748122
update @ 2024/3/10 11:08:00