logo AlgoBeat OnlineJudge
登录 注册

#215687. [ICPC 2022 Jakarta R] Sharing Bread

内存限制:256 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

There are toasters, numbered from to , from left to right. Initially, each toaster has a single piece of bread in it. There are people, numbered from to , who are one by one looking for bread among the toasters, starting from person , person , and so on.

Person starts looking from toaster () and keeps going right until they found a toaster with a piece of bread in it. In other words, person is looking for the smallest such that and toaster contains bread. If such a toaster exists, then person will take the bread from that toaster and leave; the toaster becomes empty afterward. If such a toaster does not exist, then person will leave empty-handed.

A starting sequence is fair if person starts looking from toaster and does not leave empty-handed, for all . Out of all possible starting sequences, determine how many of them are fair modulo .

输入格式

Input consists of two integers () in a single line representing the number of toasters and the number of people, respectively.

输出格式

Output an integer in a single line representing the number of fair starting sequence modulo .

样例

样例输入 1

4 3

样例输出 1

50

样例输入 2

10 1

样例输出 2

10

样例输入 3

2 2

样例输出 3

3

数据范围与提示

Explanation for the sample input/output #1

One of the possible fair starting sequences is . First, person starts looking from toaster and takes the bread from toaster . Then, person starts looking from toaster and takes the bread from toaster . Finally, person will start looking from toaster , which is currently empty. Person moves to toaster and takes the bread from toaster . Since each person gets a piece of bread, the starting sequence is fair.

Another example of fair starting sequences are , , , and . Some of the possible starting sequences that are not fair are , , , and .

Explanation for the sample input/output #2

All starting sequences are fair.

Explanation for the sample input/output #3

The only starting sequence that is not fair is . Person starts looking from toaster and takes the bread from toaster . Then, person starts looking from toaster , which is currently empty. Since there is no more toaster to the right of toaster , person will leave empty-handed.