CF2264E1.A Prime Flood (Easy Version)

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is the Easy version of the problem. The difference between the versions is that in this version, 1≤n≤30001 \le n \le 3000. You can hack only if you solved all versions of this problem.

Antigun and Lamus have flooded Madamant's house. She wants them to make the water levels equal while removing as little water as possible.

Formally, the initial water levels are given by an array a=[a1,a2,…,an]a = [a_1, a_2, \ldots, a_n]. For each hypothetical cleanup, Antigun and Lamus select a non-empty subsequence∗^{\text{∗}} bb of aa. They may perform the following operation on bb any number of times, possibly zero:

  • choose a prime number pp;
  • simultaneously decrease every element bib_i whose current value is divisible by pp by 11. All other elements remain unchanged.

Let f(b)f(b) be the maximum integer xx such that, after some sequence of operations, every element of bb is equal to xx.

Find the sum of f(b)f(b) over all non-empty subsequences bb of aa, modulo 998 244 353998\,244\,353. Subsequences formed by different choices of indices are counted separately, even if their values are equal.

Each subsequence is considered independently, starting from its original values.

∗^{\text{∗}}A sequence aa is a subsequence of a sequence bb if aa can be obtained from bb by the deletion of several (possibly, zero or all) elements from arbitrary positions.

这是本题的简单版本。两个版本的区别在于,在本版本中,1≤n≤30001 \le n \le 3000。仅当您已解决本题的所有版本后,才可进行 Hack。

Antigun 和 Lamus 淹没了 Madamant 的房子。她希望他们通过移除尽可能少的水量,使各处水位相等。

形式化地,初始水位由数组 a=[a1,a2,…,an]a = [a_1, a_2, \ldots, a_n] 给出。对于每一次假想的清理操作,Antigun 和 Lamus 从 aa 中选取一个非空子序列∗^{\text{∗}} bb。他们可在 bb 上执行如下操作任意次(包括零次):

  • 选择一个质数 pp;
  • 同时将 bb 中所有当前值能被 pp 整除的元素 bib_i 减少 11;其余元素保持不变。

令 f(b)f(b) 表示:经过若干次操作后,bb 中所有元素均可变为的最大整数 xx。

请计算 f(b)f(b) 对 aa 的所有非空子序列 bb 的求和结果,并对 998 244 353998\,244\,353 取模。即使两个子序列的元素值完全相同,只要它们由不同下标位置构成,即视为不同的子序列,需分别计数。

每个子序列均独立考虑,且均从其原始值开始操作。

∗^{\text{∗}} 序列 aa 是序列 bb 的子序列,当且仅当 aa 可通过从 bb 中删除若干(可能为零个或全部)任意位置的元素而得到。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤30001 \le t \le 3000). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤30001 \le n \le 3000) — the length of the array aa.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤n1 \le a_i \le n) — the elements of aa.

It is guaranteed that the sum of nn over all test cases does not exceed 30003000.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤30001 \le t \le 3000)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤30001 \le n \le 3000)—— 数组 aa 的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤n1 \le a_i \le n)—— 数组 aa 的元素。

保证所有测试用例的 nn 之和不超过 30003000。

输出格式

For each test case, print one integer — the sum of f(b)f(b) over all non-empty subsequences bb of aa, modulo 998 244 353998\,244\,353.

对于每个测试用例,输出一个整数——即对数组 aa 的所有非空子序列 bb,求 f(b)f(b) 的和,并对 998 244 353998\,244\,353 取模。

输入输出样例

  • 输入#1

    4
    1
    1
    4
    2 4 4 4
    4
    2 3 4 4
    6
    3 6 1 1 1 1

    输出#1

    1
    37
    34
    72

说明/提示

In the first test case, the only non-empty subsequence is [1][1], and no operation is needed. Therefore, its contribution is f([1])=1f([1]) = 1.

In the second test case, the 23−1=72^3 - 1 = 7 non-empty subsequences containing only occurrences of 44 contribute 4⋅7=284 \cdot 7 = 28. The subsequence [2][2] contributes 22. Each of the 77 subsequences containing the value 22 and at least one occurrence of 44 has f(b)=1f(b) = 1. Hence, the answer is 28+2+7=3728 + 2 + 7 = 37.

在第一个测试用例中,唯一的非空子序列为 [1][1],且无需进行任何操作。因此,其贡献值为 f([1])=1f([1]) = 1。

在第二个测试用例中,所有仅包含数字 44 的出现的 23−1=72^3 - 1 = 7 个非空子序列,其贡献值为 4⋅7=284 \cdot 7 = 28;子序列 [2][2] 的贡献值为 22;每个包含数字 22 和至少一个 44 的子序列均有 f(b)=1f(b) = 1,这样的子序列共 77 个。因此,答案为 28+2+7=3728 + 2 + 7 = 37。

输入解题思路,AI测评打分。不知道怎么写?

首页