#P14444. [ICPC 2025 Xi'an Practice] Great Indices

[ICPC 2025 Xi'an Practice] Great Indices

题目描述

You are given a sequence a1,a2,,ana_1, a_2, \cdots, a_n. For each 1in1 \leq i \leq n, index ii is called great\textit{great} if and only if the following holds:

  • There is at most one index 1jn1 \leq j \leq n such that aja_j is not a divisor of aia_i.

Your task is to find all great\textit{great} indices in the sequence.

Recall that an integer dd is a divisor of an integer nn if and only if there exists an integer kk such that n=d×kn = d \times k.

输入格式

The input consists of multiple test cases. The first line contains an integer tt (1t1051 \leq t \leq 10^5), the number of test cases. For each test case:

  • The first line contains a single integer nn (1n3×1051 \leq n \leq 3 \times 10^5), representing the length of sequence aa.
  • The second line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n (1ai1091 \leq a_i \leq 10^9), representing the given sequence.

It is guaranteed that the sum of nn over all test cases does not exceed 3×1053 \times 10^5.

输出格式

For each test case, output two lines:

  • The first line contains a single integer mm, representing the number of great\textit{great} indices.
  • The second line contains mm integers p1,p2,,pmp_1, p_2, \cdots, p_m (p1<p2<<pmp_1 < p_2 < \cdots < p_m), representing the great\textit{great} indices in increasing order\textbf{in increasing order}.
3
4
1 2 3 6
6
1 1 4 5 1 4
5
1 9 1 9 810
1
4 
2
3 6 
3
2 4 5 

提示

In the first test case:

  • When i=1i = 1, the indices jj where aja_j is not a divisor of aia_i are 22, 33, and 44. Since 3>13 > 1, index 11 is not a great\textit{great} index.
  • When i=2i = 2, there are two indices, j=3j = 3 and j=4j = 4, for which aja_j is not a divisor of aia_i.
  • When i=3i = 3, there are two indices, j=2j = 2 and j=4j = 4, for which aja_j is not a divisor of aia_i.
  • When i=4i = 4, each of aja_j is a divisor of aia_i, so that index 44 is a great\textit{great} index.

Therefore, the only great\textit{great} index is i=4i = 4.