F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Sum Plus Product

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 327    Accepted Submission(s): 241


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
2 2 2 2 10 1 2 4 8 16 32 64 128 256 512
 

Sample Output
8 579063023
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-12 12:05:32, Gzip enabled