#abc323e. E - Playlist
E - Playlist
Score : points
问题描述
Takahashi 拥有一个包含 首歌曲的播放列表。第 首歌()持续时间为 秒。
Takahashi 在时间 开始以随机播放模式播放该播放列表。
随机播放会重复以下过程:从 首歌中以相等的概率选择一首,并连续播放至结束。这里,歌曲是连续播放的:一旦一首歌结束,立即开始播放下一首被选中的歌曲。同一首歌可以连续被选中播放。
求在时间 后 秒时正在播放第一首歌的概率,结果对 取模。
如何打印模 的概率
可以证明本题中要找的概率始终是一个有理数。此外,本题的条件保证了当这个概率表示为不可约分数 时, 不会被 整除。
因此,存在一个唯一的整数 ,满足 ,且 。请报告这个 值。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi has a playlist with songs. Song lasts seconds.
Takahashi has started random play of the playlist at time .
Random play repeats the following: choose one song from the songs with equal probability and play that song to the end. Here, songs are played continuously: once a song ends, the next chosen song starts immediately. The same song can be chosen consecutively.
Find the probability that song is being played seconds after time , modulo .
How to print a probability modulo
It can be proved that the probability to be found in this problem is always a rational number. Also, the constraints of this problem guarantee that when the probability to be found is expressed as an irreducible fraction , is not divisible by .
Then, there is a unique integer between and , inclusive, such that . Report this .
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the probability, modulo , that the first song in the playlist is being played seconds after time .
Sample Input 1
3 6
3 5 6
Sample Output 1
369720131
Song will be playing seconds after time if songs are played in one of the following orders.
- Song Song Song
- Song Song
- Song Song
The probability that one of these occurs is .
We have , so you should print .
Sample Input 2
5 0
1 2 1 2 1
Sample Output 2
598946612
seconds after time , the first song to be played is still playing, so the sought probability is .
Note that different songs may have the same length.
Sample Input 3
5 10000
1 2 3 4 5
Sample Output 3
586965467
update @ 2024/3/10 01:45:01