#abc284g. G - Only Once
G - Only Once
Score : points
问题描述
对于一个长度为 的序列 ,其中包含从 1 到 (包括两端)之间的整数,以及一个整数 ,让我们定义一个长度为 的序列 如下:
- 。
- 。
另外,我们定义 为在序列 中恰好出现一次的不同整数的数量。更正式地说, 是满足存在唯一一个索引 满足 的值 的数量。
已知一个整数 。有 种可能的序列 。求所有这些序列中 的和,结果对 取模。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
For a sequence of length , , consisting of integers between and , inclusive, and an integer , let us define a sequence of length , , as follows.
- .
- .
Additionally, let us define as the number of distinct integers that occur exactly once in the sequence . More formally, is the number of values such that exactly one index satisfies .
You are given an integer . There are sequences that can be . Find the sum of over all of them, modulo .
Constraints
- and are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer as an integer.
Sample Input 1
4 100000000
Sample Output 1
624
As an example, let us consider the case .
- For : we have , where two integers, and , occur exactly once, so .
- For : we have , where one integer, , occurs exactly once, so .
- For : we have , where no integers occur exactly once, so .
- For : we have , where no integers occur exactly once, so .
Thus, we have .
If we similarly compute for the other sequences, the sum of this value over all sequences is .
Sample Input 2
7 1000000000
Sample Output 2
5817084
Sample Input 3
2023 998244353
Sample Output 3
737481389
Print the sum modulo .
Sample Input 4
100000 353442899
Sample Output 4
271798911
update @ 2024/3/10 11:54:34