codeforces-scrape

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

2173C.md (2488B)


      1 Source: https://codeforces.com/problemset/problem/2173/C
      2 
      3 C. Kanade's Perfect Multiples
      4 
      5 time limit per test
      6 
      7 2 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 We've carved those memories into ourselves... No matter how hard they were, they're the lives we carried out!
     22 
     23 — Angel Beats!
     24 
     25 In the afterlife school, Kanade studies a peculiar number game.
     26 
     27 She gives you two integers $n$ and $k$, as well as an array $a$ consisting of $n$ integers, where $1 \le a_i \le k$ holds.
     28 
     29 For an integer set $B = \{b_1, b_2, \ldots, b_m\}$ where $1\le b_i\le k$, we call it complete if and only if both of the following hold:
     30 
     31 * For each $1\le i\le n$, at least one divisor of $a_i$ is contained in $B$;
     32 * For each $1\le j\le m$, all positive multiples of $b_j$ which are less than or equal to $k$ appear in the array $a$ at least once.
     33 
     34 You have to find a complete set $B$ with minimum possible size, or determine that no such set exists.
     35 
     36 Input
     37 
     38 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
     39 
     40 The first line of each test case contains two integers $n$ and $k$ ($1\le n\le 2\cdot 10^5$, $1\le k\le 10^9$) — the length of $a$ and the upper bound of elements of $a$.
     41 
     42 The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\le a_i\le k$) — the elements of $a$.
     43 
     44 It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$.
     45 
     46 Output
     47 
     48 For each test case:
     49 
     50 * If no complete set $B$ exists, print a single integer $-1$ in the only line of output.
     51 * Otherwise:
     52   + First print a single integer $m$ ($1\le m\le n$) in the first line of output — the size of $B$. Note that you have to minimize the size of $B$.
     53   + Then output $m$ integers $b_1, b_2, \ldots, b_m$ ($1 \le b_i \le k$) in the second line — the set you constructed.
     54 
     55 If there are multiple answers, you may print any of them.
     56 
     57 Example
     58 
     59 Input
     60 
     61 ```
     62 4
     63 
     64 4 6
     65 
     66 3 2 4 6
     67 
     68 5 5
     69 
     70 1 2 3 4 5
     71 
     72 3 6
     73 
     74 2 3 6
     75 
     76 1 2
     77 
     78 2
     79 ```
     80 
     81 Output
     82 
     83 ```
     84 2
     85 
     86 2 3
     87 
     88 1
     89 
     90 1
     91 
     92 -1
     93 
     94 1
     95 
     96 2
     97 ```
     98 
     99 Note
    100 
    101 In the first test case, $B=\{2,3\}$ works. For $b=2$, all multiples $\{2,4,6\}$ (up to $k=6$) appear in $a$; for $b=3$, multiples $\{3,6\}$ appear. Every $a_i$ is divisible by $2$ or $3$. No single $b$ can satisfy both conditions, so $m=2$ is minimal.
    102 
    103 In the second test case, $B=\{1\}$ satisfies both rules since every number is divisible by $1$ and all multiples of $1$ up to $k$ appear.