#P4706. 取石子

    ID: 3577 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>枚举,暴力素数判断,质数,筛法概率论,统计

取石子

Description

Now Yopilla and yww are going to play a game.

They mark nn points on a straight line, numbered from left to right as 1,2,...,n1, 2, ..., n. Then they place some stones on each point: point ii has aia_i stones. Next, starting from Yopilla, the two players take turns. Whoever cannot make a move loses. Each move is:

The current player chooses a point xx that has stones, then chooses at least one stone from point xx, and moves all chosen stones to point x/primex / prime, where primeprime is a prime number and primexprime \mid x.

Yopilla's strategy for the very first move is random: he randomly picks a point xx that has stones, randomly chooses a positive integer number of stones yy, and randomly moves them to a reachable point zz. All stones are considered identical. In other words, two moves are different if and only if the triple (x,y,z)(x, y, z) is different. After that, both players play with optimal strategies.

Yopilla wants to predict the probability that he can win. Output the answer modulo 998244353998244353.

Input Format

The first line contains one integer nn.

The second line contains nn integers a1,a2,...,ana_1, a_2, ..., a_n.

Output Format

Output one line, representing the probability that Yopilla can win modulo 998244353998244353.

3
3 1 2
332748118

Hint

Explanation of the sample:

Point 11 has 33 stones, point 22 has 11 stone, and point 33 has 22 stones. On the first move, there are three possible moves: move the 11 stone at point 22 to point 11; move 11 stone at point 33 to point 11; move 22 stones at point 33 to point 11. Among these, only one case allows Yopilla to have a winning strategy. So the answer is

13332748118(mod998244353)\frac{1}{3} \equiv 332748118 \pmod {998244353}

For 20%20\% of the testdata, there is only one stone.

For 100%100\% of the testdata, 1n1061 \le n \le {10} ^ 6, 0ai1090 \le a_i \le {10} ^ 9. It is guaranteed that there is at least one stone not at point 11.

Translated by ChatGPT 5