Message Passing
Time limit1sMemory limit512 MB
Count the telephone calls made at time t when each informed employee calls d new people over the next d time units, modulo 31991.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Combinatorics, Math
- Solved
- No attempts yet
Problem
At 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 times. Kim wants to know how many telephone calls are made at time after the message passing starts. The rules are these.
- Each call involves exactly two employees.
- Each call takes one unit of time.
- An employee takes part in at most one call per unit of time.
- During the consecutive time units right after an employee is informed, that employee calls one uninformed employee per unit of time, so employees in total.
Kim calls exactly one employee at the moment the message passing starts, and Kim makes no other call. The case looks like this.
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 and , compute the number of telephone calls made at time after Kim started the message passing. Assume the company always has enough uninformed employees.
Input
The first line contains two integers and (, ). is the number of employees that one employee calls, and is the time that has passed since the message passing started.
Output
Let be the number of telephone calls made at time . Print on one line. For example, if , print 9.