C - Sequence Scores
Editorial
/


Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
以上 以下の整数から成る長さ の数列 に対して, を以下のように定義します.
- 長さ の数列 があり,初め全ての要素は である. を,次の操作を繰り返して を に等しくするための最小の操作回数とする.
- と を指定する. に対して を で置き換える.
として考えられる数列は 通りあります.これら全ての数列に対する の和を で割った余りを求めてください.
制約
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる.
出力
全ての数列に対する の和を で割った余りを出力せよ.
入力例 1Copy
Copy
2 3
出力例 1Copy
Copy
15
通りの数列と,それに対する の値は以下の通りです.
- のとき, として 回の操作で可能なので, です.
- のとき, , として 回の操作で可能なので, です.
- のとき, , として 回の操作で可能なので, です.
- のとき, , として 回の操作で可能なので, です.
- のとき, として 回の操作で可能なので, です.
- のとき, , として 回の操作で可能なので, です.
- のとき, , として 回の操作で可能なので, です.
- のとき, , として 回の操作で可能なので, です.
- のとき, として 回の操作で可能なので, です.
これらの和は です.
入力例 2Copy
Copy
3 2
出力例 2Copy
Copy
15
入力例 3Copy
Copy
34 56
出力例 3Copy
Copy
649717324
Score : points
Problem Statement
For a sequence of length consisting of integers between and (inclusive), let us define as follows:
- We have a sequence of length , where every element is initially . is the minimum number of operations required to make equal by repeating the following operation:
- Specify and , then replace with for each .
Find the sum, modulo , of over all sequences that can be .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the sum of over all sequences , modulo .
Sample Input 1Copy
Copy
2 3
Sample Output 1Copy
Copy
15
The sequences and the value of for those are as follows:
- For , we can make equal it with one operation with , so .
- For , we can make equal it with two operations with and , so .
- For , we can make equal it with two operations with and , so .
- For , we can make equal it with two operations with and , so .
- For , we can make equal it with one operation with , so .
- For , we can make equal it with two operations with , , so .
- For , we can make equal it with two operations with and so .
- For , we can make equal it with two operations with and , so .
- For , we can make equal it with one operation with , so .
The sum of these values is .
Sample Input 2Copy
Copy
3 2
Sample Output 2Copy
Copy
15
Sample Input 3Copy
Copy
34 56
Sample Output 3Copy
Copy
649717324