CF2258E.DivMEX

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array a1,a2,…,ana_1, a_2, \ldots, a_n of positive integers.

Let f(l,r)f(l,r) for 1≤l≤r≤n1 \leq l \leq r \leq n be the smallest positive integer that doesn't divide lcm⁡(al,al+1,…,ar)\operatorname{lcm}(a_l, a_{l+1}, \ldots, a_r). Here, lcm⁡\operatorname{lcm} of an array of integers denotes the least common multiple (LCM) of these integers.

Determine every positive integer xx such that there exists a pair of integers (l,r)(l,r) such that 1≤l≤r≤n1 \leq l \leq r \leq n and f(l,r)=xf(l,r) = x.

给你一个由正整数构成的数组 a1,a2,…,ana_1, a_2, \ldots, a_n。

对任意满足 1≤l≤r≤n1 \leq l \leq r \leq n 的整数对 (l,r)(l,r),定义 f(l,r)f(l,r) 为不能整除 lcm⁡(al,al+1,…,ar)\operatorname{lcm}(a_l, a_{l+1}, \ldots, a_r) 的最小正整数。其中,lcm⁡\operatorname{lcm} 表示该整数数组的最小公倍数(LCM)。

请确定所有满足如下条件的正整数 xx:存在整数对 (l,r)(l,r),使得 1≤l≤r≤n1 \leq l \leq r \leq n 且 f(l,r)=xf(l,r) = x。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5), denoting the size of the array.

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

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5),表示数组的大小。

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

保证所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output two lines.

The first line should contain a single integer kk — the number of suitable integers xx.

The second line should contain kk integers x1<x2<…<xkx_1 \lt x_2 \lt \ldots \lt x_k, the suitable integers in increasing order.

对于每个测试用例,输出两行。

第一行应包含一个整数 kk —— 满足条件的整数 xx 的个数。

第二行应包含 kk 个整数 x1<x2<…<xkx_1 \lt x_2 \lt \ldots \lt x_k,即按升序排列的所有满足条件的整数。

输入输出样例

  • 输入#1

    3
    1
    1
    3
    2 3 1
    5
    4 3 1 3 4

    输出#1

    1
    2 
    3
    2 3 4 
    3
    2 3 5

说明/提示

In the first test case, the only (l,r)(l,r) pair is (1,1)(1,1), and f(1,1)=2f(1,1) = 2.

In the second test case, (l,r)=(1,1)(l,r)=(1,1) yields the set of divisors 1,2{ 1,2 }, (l,r)=(1,2)(l,r)=(1,2) yields the set of divisors 1,2,3,6{ 1, 2, 3, 6}, and (l,r)=(2,2)(l,r)=(2,2) yields the set of divisors 1,3{ 1, 3 }. This means f(1,1)=3f(1,1)=3, f(1,2)=4f(1,2)=4, and f(2,2)=2f(2,2)=2. Since no other (l,r)(l,r) pair produces a different ff value, the answer is [2,3,4][2,3,4].

For the last test case, f(2,2)=2f(2,2)=2, f(1,1)=3f(1,1)=3, and f(1,5)=5f(1,5)=5. It can be seen that no other values can be obtained.

在第一个测试用例中,唯一的 (l,r)(l,r) 对是 (1,1)(1,1),且 f(1,1)=2f(1,1) = 2。

在第二个测试用例中,(l,r)=(1,1)(l,r)=(1,1) 得到的约数集合为 {1,2}\{ 1,2 \},(l,r)=(1,2)(l,r)=(1,2) 得到的约数集合为 {1,2,3,6}\{ 1, 2, 3, 6\},而 (l,r)=(2,2)(l,r)=(2,2) 得到的约数集合为 {1,3}\{ 1, 3 \}。这意味着 f(1,1)=3f(1,1)=3,f(1,2)=4f(1,2)=4,且 f(2,2)=2f(2,2)=2。由于不存在其他 (l,r)(l,r) 对能产生不同的 ff 值,答案为 [2,3,4][2,3,4]。

在最后一个测试用例中,f(2,2)=2f(2,2)=2,f(1,1)=3f(1,1)=3,且 f(1,5)=5f(1,5)=5。可以验证无法得到其他取值。

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

首页