Starflower Serenade (Hard)
Time limit2sMemory limit512 MB
Find the expected number of seeds planted until each flower kind i blooms at least M_i times, printed as R modulo 998244353.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Probability, Math
- Solved
- No attempts yet
Problem
The king of the winter kingdom decided to gather the most beautiful flowers and make a garland for the queen, who loves flowers. The flowers she likes are special. They bloom only after a magic seed is planted and starlight falls on it. There are kinds of flowers that can bloom from a magic seed, and the flower of the -th kind blooms with probability . Whether a seed blooms does not depend on other seeds. To make the garland, at least flowers of each kind are needed. Suppose flowers bloom from seeds one at a time until the garland is complete. What is the expected number of seeds needed?
Input
The first line contains an integer (), the number of kinds of flowers. Each of the next lines contains two integers: (), the number of flowers of kind that are needed, and , the weight of the blooming probability. , and the probability that a flower of kind blooms is .
Output
Print the expected number of seeds needed to make the garland. Under the given conditions, the value is always a positive rational number. Write it as , where and are coprime positive integers. Print the unique integer with such that .