问题 B: Random Nim Game

内存限制:512 MB 时间限制:6 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:2

题目描述

Nim is a two-player mathematic game of strategy in which players take turns removing stones from distinct heaps. On each turn, a player must remove at least one stone, and may remove any number of stones provided they all come from the same heap. The person who makes the last move (i.e., who takes the last stone) wins.

Alice and Bob is tired of playing Nim under the standard rule, so they want to play Nim randomly. On each turn, a player must select any one of the heaps. Assuming the heap he selects contains x stones, he will randomly choose a integer number y from [1, x], and remove y stone(s) from the heap. Note that the selected heap can be arbitrary.

Alice will play first. Calculate the probability of Alice winning, modulo 998244353.

输入格式

The input consists of multiple test cases. The first line contains a single integer T(1T500) - the number of test cases. Description of the test cases follows.

The first line of each test case contains one integer n(1n10^5) - the number of heap(s).

The second line contains n integers a_1, a_2,……,a_n (1ai10^9) - the number of stone(s) of each heap.

It's guaranteed that n10^6

输出格式

For each test case, print a single integer - the probability of Alice winning, modulo 998244353.

输入样例 复制

2
2
1 1
1
2

输出样例 复制

0
499122177

分类标签