CF2258E.DivMEX
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a1,a2,…,an of positive integers.
Let f(l,r) for 1≤l≤r≤n be the smallest positive integer that doesn't divide lcm(al,al+1,…,ar). Here, lcm of an array of integers denotes the least common multiple (LCM) of these integers.
Determine every positive integer x such that there exists a pair of integers (l,r) such that 1≤l≤r≤n and f(l,r)=x.
给你一个由正整数构成的数组 a1,a2,…,an。
对任意满足 1≤l≤r≤n 的整数对 (l,r),定义 f(l,r) 为不能整除 lcm(al,al+1,…,ar) 的最小正整数。其中,lcm 表示该整数数组的最小公倍数(LCM)。
请确定所有满足如下条件的正整数 x:存在整数对 (l,r),使得 1≤l≤r≤n 且 f(l,r)=x。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains n (1≤n≤2⋅105), denoting the size of the array.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤n).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105),表示数组的大小。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤n)。
保证所有测试用例的 n 值之和不超过 2⋅105。
输出格式
For each test case, output two lines.
The first line should contain a single integer k — the number of suitable integers x.
The second line should contain k integers x1<x2<…<xk, the suitable integers in increasing order.
对于每个测试用例,输出两行。
第一行应包含一个整数 k —— 满足条件的整数 x 的个数。
第二行应包含 k 个整数 x1<x2<…<xk,即按升序排列的所有满足条件的整数。
输入输出样例
输入#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) pair is (1,1), and f(1,1)=2.
In the second test case, (l,r)=(1,1) yields the set of divisors 1,2, (l,r)=(1,2) yields the set of divisors 1,2,3,6, and (l,r)=(2,2) yields the set of divisors 1,3. This means f(1,1)=3, f(1,2)=4, and f(2,2)=2. Since no other (l,r) pair produces a different f value, the answer is [2,3,4].
For the last test case, f(2,2)=2, f(1,1)=3, and f(1,5)=5. It can be seen that no other values can be obtained.
在第一个测试用例中,唯一的 (l,r) 对是 (1,1),且 f(1,1)=2。
在第二个测试用例中,(l,r)=(1,1) 得到的约数集合为 {1,2},(l,r)=(1,2) 得到的约数集合为 {1,2,3,6},而 (l,r)=(2,2) 得到的约数集合为 {1,3}。这意味着 f(1,1)=3,f(1,2)=4,且 f(2,2)=2。由于不存在其他 (l,r) 对能产生不同的 f 值,答案为 [2,3,4]。
在最后一个测试用例中,f(2,2)=2,f(1,1)=3,且 f(1,5)=5。可以验证无法得到其他取值。
输入解题思路,AI测评打分。不知道怎么写?