QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#14678. 优秀下标

Statistics

给你一个序列 $a_1, a_2, \dots, a_n$。对于每个 $1 \le i \le n$,当下标 $i$ 满足以下条件时,被称为优秀的(great):

  • 至多存在一个下标 $1 \le j \le n$,使得 $a_j$ 不是 $a_i$ 的因数。

你的任务是找到序列中所有优秀的下标。

回想一下,整数 $d$ 是整数 $n$ 的因数,当且仅当存在一个整数 $k$ 使得 $n = d \times k$。

输入格式

输入包含多组测试数据。第一行包含一个整数 $t$ ($1 \le t \le 10^5$),表示测试数据的组数。对于每组测试数据:

  • 第一行包含一个整数 $n$ ($1 \le n \le 3 \times 10^5$),表示序列 $a$ 的长度。
  • 第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$),表示给定的序列。

保证所有测试数据的 $n$ 之和不超过 $3 \times 10^5$。

输出格式

对于每组测试数据,输出两行:

  • 第一行包含一个整数 $m$,表示优秀下标的数量。
  • 第二行包含 $m$ 个整数 $p_1, p_2, \dots, p_m$ ($p_1 < p_2 < \dots < p_m$),表示按升序排列的优秀下标。

样例

输入样例 1

3
4
1 2 3 6
6
1 1 4 5 1 4
5
1 9 1 9 810

输出样例 1

1
4
2
3 6
3
2 4 5

说明

在第一组测试数据中:

  • 当 $i = 1$ 时,使得 $a_j$ 不是 $a_1$ 的因数的下标 $j$ 有 2, 3 和 4。由于 $3 > 1$,因此下标 1 不是优秀的下标。
  • 当 $i = 2$ 时,有两个下标 $j = 3$ 和 $j = 4$ 使得 $a_j$ 不是 $a_2$ 的因数。
  • 当 $i = 3$ 时,有两个下标 $j = 2$ 和 $j = 4$ 使得 $a_j$ 不是 $a_3$ 的因数。
  • 当 $i = 4$ 时,每个 $a_j$ 都是 $a_4$ 的因数,因此下标 4 是一个优秀的下标。

因此,唯一的优秀下标是 $i = 4$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.