#abc307e. E - Distinct Adjacent
E - Distinct Adjacent
Score : points
问题描述
设有 名人员,编号从 到 ,他们站成一个圆圈。其中,编号为 的人站在编号为 的人的右边,编号为 的人站在编号为 的人的右边,依此类推,编号为 的人站在编号为 的人的右边。
我们将给这 名人员每人分配一个介于 和 (包含两端点)之间的整数。
在 种分配整数的方式中,找出满足没有相邻两人分配到相同整数的方法总数,结果对 取模。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There are people numbered from to standing in a circle. Person is to the right of person , person is to the right of person , ..., and person is to the right of person .
We will give each of the people an integer between and , inclusive.
Among the ways to distribute integers, find the number, modulo , of such ways that no two adjacent people have the same integer.
Constraints
- and are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 3
Sample Output 1
6
There are six desired ways, where the integers given to persons are .
Sample Input 2
4 2
Sample Output 2
2
There are two desired ways, where the integers given to persons are .
Sample Input 3
987654 456789
Sample Output 3
778634319
Be sure to find the number modulo .
update @ 2024/3/10 08:41:49