|
||||||||||
Sum Plus ProductTime Limit: 20000/10000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 336 Accepted Submission(s): 250 Problem Description <tt>triplea</tt> has a box with $n(n\geq 1)$ balls inside, where on each of the balls there is an integer written. When there are <strong> at least two</strong> balls inside the box, <tt>triplea</tt> will do the following operation repeatedly: <ol> <li> Take two balls from the box, uniformly and independently at random. </li> <li> Supposes the numbers written on the two balls are $a$ and $b$, respectively, then <tt>triplea</tt> will put a new ball in the box on which a number $S+P$ is written, where $S=a+b$ is the sum of $a$ and $b$, and $P=ab$ is the product of $a$ and $b$. </li> </ol> The operation will end when there is only one ball in the box. <tt>triplea</tt> wonders, what is the expected value of the number written on the last ball? He gets the answer immediately, and leaves this as an exercise for the reader, namely, you. Input The first line of input consists of an integer $T(1\leq T\leq 20)$, denoting the number of test cases. For each test case, the first line of input consists of an integer $n(1\leq n\leq 500)$, denoting the initial number of balls inside the box. The next line contains $n$ integers $a_1,a_2,\dots,a_n(0\leq a_i\lt 998244353)$, denoting the number written on each ball in the box, initially. Output For each test case, output an integer in one line, denoting the expected value of the number written on the last ball. Under the input constraints of this problem, it can be shown that the answer can be written as $\frac{P}{Q}$, where $P$ and $Q$ are coprime integers and $Q\not\equiv 0\pmod {998244353}$. You need to output $P\cdot Q^{-1}\pmod{998244353}$ as an answer, where $Q^{-1}$ is the modular inverse of $Q$ with respect to $998244353$. Sample Input
Sample Output
Source | ||||||||||
|