CF2193E.Product Queries

普及-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Today, Sabyrzhan was called to the board with an array aa of length nn and was assigned an officer's task — to answer nn questions.

In the ii-th question, it is required to determine the minimum number of elements from the array that need to be selected from the board (it is allowed to use the same element multiple times) so that their product is exactly equal to ii, or to report that it is impossible to achieve such a product.

Note that at least one element must be selected.

今天,萨比尔江被叫到黑板前,面对一个长度为 nn 的数组 aa,并被布置了一项“军官任务”——回答 nn 个问题。

在第 ii 个问题中,需要确定:从该数组中至少选取多少个元素(允许重复选取同一元素),使得它们的乘积恰好等于 ii;若无法实现这样的乘积,则报告“不可能”。

注意:必须至少选取一个元素。

输入格式

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

The first line of each test case contains one integer nn (1≤n≤3⋅1051 \le n \le 3 \cdot 10 ^ 5).

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 the values of nn across all test cases does not exceed 3⋅1053 \cdot 10 ^ 5.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤3⋅1051 \le n \le 3 \cdot 10 ^ 5)。

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

保证所有测试用例中 nn 的总和不超过 3⋅1053 \cdot 10 ^ 5。

输出格式

For the ii-th question, output one integer — the minimum number of elements from the array required to obtain a product equal to ii, or −1−1 if it is impossible to achieve such a product.

对于第 ii 个问题,输出一个整数——为得到乘积恰好等于 ii 所需的数组中元素的最少个数;若无法得到该乘积,则输出 −1-1。

输入输出样例

  • 输入#1

    6
    8
    3 2 2 3 7 3 6 7
    5
    1 2 3 4 5
    3
    1 1 1
    10
    2 1 2 1 3 5 5 7 7 7
    4
    1 1 2 2
    1
    1

    输出#1

    -1 1 1 2 -1 1 1 3
    1 1 1 1 1
    1 -1 -1
    1 1 1 2 1 2 1 3 2 2
    1 1 -1 2
    1

说明/提示

Consider the first test case. The products can be obtained as follows:

  • 11 cannot be obtained.
  • 22 can be obtained by selecting a2a_2.
  • 33 can be obtained by selecting a1a_1.
  • 44 can be obtained by selecting a2a_2 twice.
  • 55 cannot be obtained.
  • 66 can be obtained by selecting a7a_7.
  • 77 can be obtained by selecting a5a_5.
  • 88 can be obtained by selecting a2a_2 three times.

考虑第一个测试用例。这些乘积可以如下得到:

  • 11 无法得到。
  • 22 可通过选择 a2a_2 得到。
  • 33 可通过选择 a1a_1 得到。
  • 44 可通过选择 a2a_2 两次得到。
  • 55 无法得到。
  • 66 可通过选择 a7a_7 得到。
  • 77 可通过选择 a5a_5 得到。
  • 88 可通过选择 a2a_2 三次得到。

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

首页