Count the telephone calls made at time t when each informed employee calls d new people over the next d time units, modulo 31991.
Medium6Dynamic programmingCombinatoricsMathNo attempts yetTime limit1sMemory limit512 MBAt International Computer Products Company (ICPC), the employer often has to pass an important message to every employee. The message spreads along the organizational reporting lines as a chain of telephone calls. Kim, the employer of ICPC, is rebuilding the message passing system so that no employee calls other employees more than d times. Kim wants to know how many telephone calls are made at time t after the message passing starts. The rules are these.
Kim calls exactly one employee at the moment the message passing starts, and Kim makes no other call. The case d=2 looks like this.
| Time t | Telephone calls | Number of calls at time t |
|---|---|---|
| 0 | Kim starts the message passing by calling A. | 1 |
| 1 | A calls B. | 1 |
| 2 | A calls C, and B calls D. | 2 |
| 3 | B, C, and D call E, F, and G. | 3 |
Kim starts the message passing by calling A at time 0, and that call takes one unit of time. At time 1, A is the only employee who knows the message, so A calls the uninformed employee B. At time 2, both A and B know the message, and they call the uninformed employees C and D. No employee makes more than two calls here, so A stops calling after time 2. Three telephone calls are made at time 3.
Given d and t, compute the number of telephone calls made at time t after Kim started the message passing. Assume the company always has enough uninformed employees.
The first line contains two integers d and t (2≤d≤50, 1≤t≤2×109). d is the number of employees that one employee calls, and t is the time that has passed since the message passing started.
Let m be the number of telephone calls made at time t. Print mmod31991 on one line. For example, if m=32000, print 9.