#P5401. [CTS2019] 珍珠
[CTS2019] 珍珠
Background
Time passes and everything changes.
In front of Baiyun, only a blurred scene remains.
In the vague view, it saw many small pearls, some shining with colorful light. These pearls were left by the white rabbit. Each pearl has a color, randomly chosen from colors.
Baiyun wants to put these pearls into some small bottles. Each bottle can hold exactly two pearls. It also has requirements: every bottle must be full, and the two pearls in it must have the same color.
Baiyun hopes to obtain at least full bottles of pearls, and it wants to know the probability that its wish can be achieved.
Problem Description
There are independent uniformly random integer variables in the range .
Find the probability that we can choose at least bottles, such that there exists a way to select some variables and put each selected variable into a bottle, satisfying that each bottle contains exactly two variables with the same value.
Output the value of the probability multiplied by , taken modulo . For the modulo details, refer to Problem 1.
Input Format
The input contains only one line with three integers separated by spaces.
Output Format
Output one integer, representing the required value of the probability multiplied by modulo .
2 2 1
2
8 10 4
301103104
998 1000 500
762913089
Hint
Sample 1 Explanation
Case : the first variable is , and the second variable is .
Case : the first variable is , and the second variable is .
Case : the first variable is , and the second variable is .
Case : the first variable is , and the second variable is .
In cases and , we can put the two variables into one bottle.
In cases and , the two variables have different values, so they cannot be put into the same bottle.
Testdata Convention

All test points satisfy $0 \leqslant m \leqslant 10^9,1 \leqslant n \leqslant 10^9,1 \leqslant D \leqslant 10^5$。
Translated by ChatGPT 5