CF2183E.LCM is Legendary Counting Master

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given a sequence aa of length nn and a positive integer mm. Each element of aa is an integer in the range [0,m][0, m].

A sequence aa is considered good if and only if the following two conditions hold:

  • a1<a2<a3<…<ana_1 \lt a_2 \lt a_3 \lt \ldots \lt a_n, and
  • 1lcm⁡(a1,a2)+1lcm⁡(a2,a3)+…+1lcm⁡(an−1,an)+1lcm⁡(an,a1)≥1\frac{1}{\operatorname{lcm}(a_1,a_2)}+\frac{1}{\operatorname{lcm}(a_2,a_3)}+\ldots+\frac{1}{\operatorname{lcm}(a_{n-1},a_n)}+\color{red}{\frac{1}{\operatorname{lcm}(a_n,a_1)}}\ge1.∗^{\text{∗}}

You need to replace all zeros in aa with integers from the range [1,m][1, m]. Calculate the number of different ways to replace the zeros such that the resulting sequence aa is good.

Print the answer modulo 998 244 353998\,244\,353.

∗^{\text{∗}}The Least common multiple (lcm⁡\operatorname{lcm}) of two positive integers is the smallest positive integer that is a multiple of both. For example, lcm⁡(2,3)=6,lcm⁡(4,6)=12\operatorname{lcm}(2,3)=6, \operatorname{lcm}(4,6)=12.

给你一个长度为 nn 的序列 aa 和一个正整数 mm。序列 aa 中每个元素均为区间 [0,m][0, m] 内的整数。

当且仅当满足以下两个条件时,序列 aa 被称为好序列:

  • a1<a2<a3<…<ana_1 \lt a_2 \lt a_3 \lt \ldots \lt a_n,且
  • 1lcm⁡(a1,a2)+1lcm⁡(a2,a3)+…+1lcm⁡(an−1,an)+1lcm⁡(an,a1)≥1\frac{1}{\operatorname{lcm}(a_1,a_2)}+\frac{1}{\operatorname{lcm}(a_2,a_3)}+\ldots+\frac{1}{\operatorname{lcm}(a_{n-1},a_n)}+\color{red}{\frac{1}{\operatorname{lcm}(a_n,a_1)}}\ge1.∗^{\text{∗}}

你需要将 aa 中所有 00 替换为区间 [1,m][1, m] 内的整数。求有多少种不同的替换方式,使得替换后得到的序列 aa 是好序列。

请输出答案对 998 244 353998\,244\,353 取模的结果。

∗^{\text{∗}} 两个正整数的最小公倍数(lcm⁡\operatorname{lcm})是指同时是这两个正整数的倍数的最小正整数。例如:lcm⁡(2,3)=6\operatorname{lcm}(2,3)=6,lcm⁡(4,6)=12\operatorname{lcm}(4,6)=12。

输入格式

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

The first line of each test case contains two integers nn and mm (2≤n≤m≤30002 \le n\le m \le 3000).

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤m0 \le a_i \le m).

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

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

每个测试用例的第一行包含两个整数 nn 和 mm(2≤n≤m≤30002 \le n\le m \le 3000)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤m0 \le a_i \le m)。

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

输出格式

For each test case, output a single integer — the number of ways to complete the sequence so that it becomes good, modulo 998 244 353998\,244\,353.

对于每个测试用例,输出一个整数——使该序列变为“好”序列的补全方案数,对 998 244 353998\,244\,353 取模。

输入输出样例

  • 输入#1

    5
    4 6
    1 0 0 6
    2 2
    2 1
    5 24
    0 0 4 0 0
    5 6
    0 0 6 0 0
    20 2000
    1 0 0 0 0 14 0 0 0 0 0 0 0 0 0 514 0 0 0 0

    输出#1

    2
    0
    10
    0
    973702700

说明/提示

In the first test case, there are 22 ways to replace the zeros such that the sequence becomes good:

  • [1,2,3,6][1, 2, 3, 6]: The sum is 1lcm⁡(1,2)+1lcm⁡(2,3)+1lcm⁡(3,6)+1lcm⁡(6,1)=12+16+16+16=1\frac{1}{\operatorname{lcm}(1, 2)} + \frac{1}{\operatorname{lcm}(2, 3)} + \frac{1}{\operatorname{lcm}(3, 6)} + \frac{1}{\operatorname{lcm}(6, 1)} = \frac{1}{2} + \frac{1}{6} + \frac{1}{6} + \frac{1}{6} = 1.
  • [1,2,4,6][1, 2, 4, 6]: The sum is 1lcm⁡(1,2)+1lcm⁡(2,4)+1lcm⁡(4,6)+1lcm⁡(6,1)=12+14+112+16=1\frac{1}{\operatorname{lcm}(1, 2)} + \frac{1}{\operatorname{lcm}(2, 4)} + \frac{1}{\operatorname{lcm}(4, 6)} + \frac{1}{\operatorname{lcm}(6, 1)} = \frac{1}{2} + \frac{1}{4} + \frac{1}{12} + \frac{1}{6} = 1.

In the second test case, the initial sequence is [2,1][2, 1]. Since 2≮12 \not \lt 1, the strictly increasing condition is not met, so the answer is 00.

In the fourth test case, the sequence is fixed to be [0,0,6,0,0][0, 0, 6, 0, 0] with m=6m=6. The third element is 66. Since the sequence must be strictly increasing and elements cannot exceed 66, we would need 6<a4<a5≤66 \lt a_4 \lt a_5 \le 6, which is impossible.

在第一个测试用例中,有 22 种方式将零替换为正整数,使得序列变为“好”的序列:

  • [1,2,3,6][1, 2, 3, 6]:其和为 1lcm⁡(1,2)+1lcm⁡(2,3)+1lcm⁡(3,6)+1lcm⁡(6,1)=12+16+16+16=1\frac{1}{\operatorname{lcm}(1, 2)} + \frac{1}{\operatorname{lcm}(2, 3)} + \frac{1}{\operatorname{lcm}(3, 6)} + \frac{1}{\operatorname{lcm}(6, 1)} = \frac{1}{2} + \frac{1}{6} + \frac{1}{6} + \frac{1}{6} = 1。
  • [1,2,4,6][1, 2, 4, 6]:其和为 1lcm⁡(1,2)+1lcm⁡(2,4)+1lcm⁡(4,6)+1lcm⁡(6,1)=12+14+112+16=1\frac{1}{\operatorname{lcm}(1, 2)} + \frac{1}{\operatorname{lcm}(2, 4)} + \frac{1}{\operatorname{lcm}(4, 6)} + \frac{1}{\operatorname{lcm}(6, 1)} = \frac{1}{2} + \frac{1}{4} + \frac{1}{12} + \frac{1}{6} = 1。

在第二个测试用例中,初始序列为 [2,1][2, 1]。由于 2≮12 \not \lt 1,不满足严格递增条件,因此答案为 00。

在第四个测试用例中,序列为固定的 [0,0,6,0,0][0, 0, 6, 0, 0],且 m=6m=6。第三个元素为 66。由于序列必须严格递增,且所有元素不能超过 66,因此需满足 6<a4<a5≤66 \lt a_4 \lt a_5 \le 6,这是不可能的。

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

首页