codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

2193E.md (1978B)


      1 Source: https://codeforces.com/problemset/problem/2193/E
      2 
      3 E. Product Queries
      4 
      5 time limit per test
      6 
      7 3 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Today, Sabyrzhan was called to the board with an array $a$ of length $n$ and was assigned an officer's task — to answer $n$ questions.
     22 
     23 In the $i$-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 $i$, or to report that it is impossible to achieve such a product.
     24 
     25 Note that at least one element must be selected.
     26 
     27 Input
     28 
     29 Each test consists of several test cases. The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows.
     30 
     31 The first line of each test case contains one integer $n$ ($1 \le n \le 3 \cdot 10 ^ 5$).
     32 
     33 The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$).
     34 
     35 It is guaranteed that the sum of the values of $n$ across all test cases does not exceed $3 \cdot 10 ^ 5$.
     36 
     37 Output
     38 
     39 For the $i$-th question, output one integer — the minimum number of elements from the array required to obtain a product equal to $i$, or $−1$ if it is impossible to achieve such a product.
     40 
     41 Example
     42 
     43 Input
     44 
     45 ```
     46 6
     47 
     48 8
     49 
     50 3 2 2 3 7 3 6 7
     51 
     52 5
     53 
     54 1 2 3 4 5
     55 
     56 3
     57 
     58 1 1 1
     59 
     60 10
     61 
     62 2 1 2 1 3 5 5 7 7 7
     63 
     64 4
     65 
     66 1 1 2 2
     67 
     68 1
     69 
     70 1
     71 ```
     72 
     73 Output
     74 
     75 ```
     76 -1 1 1 2 -1 1 1 3
     77 
     78 1 1 1 1 1
     79 
     80 1 -1 -1
     81 
     82 1 1 1 2 1 2 1 3 2 2
     83 
     84 1 1 -1 2
     85 
     86 1
     87 ```
     88 
     89 Note
     90 
     91 Consider the first test case. The products can be obtained as follows:
     92 
     93 * $1$ cannot be obtained.
     94 * $2$ can be obtained by selecting $a_2$.
     95 * $3$ can be obtained by selecting $a_1$.
     96 * $4$ can be obtained by selecting $a_2$ twice.
     97 * $5$ cannot be obtained.
     98 * $6$ can be obtained by selecting $a_7$.
     99 * $7$ can be obtained by selecting $a_5$.
    100 * $8$ can be obtained by selecting $a_2$ three times.