luogu#P9174. [COCI 2022/2023 #4] Bojanje
[COCI 2022/2023 #4] Bojanje
Problem Description
Oliver is a little yellow duck who can not only find bugs but also likes painting. His latest painting has sections, and each section is painted with a different color. After that, he received a lot of criticism because his painting was too predictable. He decided to modify his painting for iterations. In each iteration, he will do the following:
- Oliver uniformly randomly chooses an index , and then remembers the color of section in the painting.
- Oliver uniformly randomly chooses an index . He repaints section to be the same color as section . If section already has the same color as section , then nothing changes. Note that may equal .
Now, Oliver is afraid that his painting will become too plain or boring. He thinks a painting is good if it contains at least different colors. Please help him compute the probability that the final painting is good.
Input Format
The first line contains three integers , with meanings as described in the statement.
Output Format
Output one number in a single line, representing the answer modulo .
Formally, let . It can be shown that the answer can be written as an irreducible fraction , where and are integers and . Output . In other words, output the integer such that and .
2 1 2
500000004
10 2 5
1
3 141592653589793 2
468261332
Hint
Explanation for Sample : There are two colors in the painting, so after one iteration, the probability that the painting stays the same as before any operation is .
Explanation for Sample : After two iterations, it is impossible for the number of different colors to decrease from to less than , so in all cases the painting will have at least different colors.
| Subtask ID | Additional Constraints | Score |
|---|---|---|
| Sample | ||
| No additional constraints |
Translated by ChatGPT 5