#P7607. [THUPC 2021] 赌徒问题

[THUPC 2021] 赌徒问题

Description

Two gamblers, Picar and Roman, of unknown nationality and age, are playing a game.

As mentioned in some classic gambling-related problems, this game is purely random.

In each round, every gambler who participates must first choose a number to bet on and pay the bet amount to the system (let the currency unit used in the game be G). The chosen number can be any integer from 11 to nn (where nn is a fixed positive integer), and number ii corresponds to a positive integer weight aia_i. Let s=i=1nais=\sum_{i=1}^n a_i. Then, in each round, the system always selects number ii with probability ai/sa_i/s. After all gamblers finish betting, the system randomly picks one number as the winning number according to the given probabilities. A gambler who bet on the winning number can receive a prize based on the bet amount and the probability of the winning number, while gamblers who bet on other numbers receive no prize.

As for the payout ratio, a natural idea is: no matter which number a gambler bets on, their expected prize should equal their bet amount. That is, if a gambler pays xx G for number ii, then if they win, they should receive a prize of sx/aisx/a_i.

A small flaw of this game is that the minimum denomination of currency G is 11 G, meaning the system cannot pay back fractional parts of prizes. To avoid this, the bet amount each time must be a positive integer multiple of kk (where kk is a fixed positive integer). The game designer must ensure that after kk is fixed, ksk s is a positive integer multiple of every aia_i (i=1,,ni = 1, \ldots , n), so that no non-integer values appear when calculating prizes.

Picar and Roman find this game interesting and want to play several rounds under different parameters. But they do not like very large numbers, so ss cannot exceed a given positive integer mm (obviously, since the sum of weights is at most mm, each weight is also at most mm). For two schemes with the same set of weights, merely permuting the order of weights does not change the experience much, so Picar and Roman believe that two sets of weight parameters are essentially different if and only if the corresponding multisets are different. In other words, if we sort the two sets of weight parameters a1,,ana_1, \ldots, a_n and b1,,bnb_1, \ldots, b_n in nondecreasing order to get 1α1α2αn1\le\alpha_1\le\alpha_2\le\cdots\le\alpha_n and 1β1β2βn1\le\beta_1\le\beta_2\le\cdots\le\beta_n, then the two sets are essentially different if and only if there exists an index i{1,,n}i\in\left\{1, \ldots, n\right\} such that αiβi\alpha_i \ne \beta_i.

Picar and Roman want to know: given n,m,kn, m, k, how many essentially different parameter schemes satisfy the “requirements”. Note that since the stingy Picar and Roman only give you kk, you must ensure that in every scheme you count, ksk s is a positive integer multiple of every weight aia_i (i=1,,ni = 1, \ldots , n).

Input Format

The input contains only one line with three positive integers n,m,kn, m, k, separated by a single space.

Output Format

Output a non-negative integer, the number of schemes modulo 109+7{10}^9+7.

3 9 1

6

3 9 10

13

10 2000 20201003

365520548

Hint

Sample Explanation #1

The schemes that satisfy the requirements are:

  1. 3=1+1+13=1+1+1.
  2. 4=1+1+24=1+1+2.
  3. 6=1+2+36=1+2+3.
  4. 6=2+2+26=2+2+2.
  5. 8=2+2+48=2+2+4.
  6. 9=3+3+39=3+3+3.

Please note that the schemes in this problem are order-independent.

Sample Explanation #2

Besides the schemes in Sample #1, there are also:

  1. 5=1+2+25=1+2+2.
  2. 6=1+1+46=1+1+4.
  3. 7=1+1+57=1+1+5.
  4. 8=1+2+58=1+2+5.
  5. 9=1+2+69=1+2+6.
  6. 9=1+3+59=1+3+5.
  7. 9=2+2+59=2+2+5.

Constraints

For 100%100\% of the testdata, it is guaranteed that 1n101\le n\le 10, 1m20001\le m \le 2000, 1k1091\le k \le 10^9.

Hint

Gambling is risky; it is recommended to stay away from gambling.

Before submitting, please make sure you correctly understand the constraints. If your understanding is not correct, you may get a Wrong Answer result.

Source

From the 2021 Tsinghua University Student Programming Contest and Collegiate Invitational (THUPC2021).

Resources such as editorials can be found at https://github.com/yylidiw/thupc_1/tree/master.

Translated by ChatGPT 5