luogu#P5020. [NOIP 2018 提高组] 货币系统
[NOIP 2018 提高组] 货币系统
Background
NOIP 2018 Senior D1T2.
Problem Description
In the netizens’ kingdom, there are different denominations of currency. The denomination of the -th currency is . You may assume that there are infinitely many bills of each denomination. For convenience, we denote the currency system with types of currency and denomination array as .
In a perfect currency system, every non-negative integer amount should be representable. That is, for every non-negative integer , there exist non-negative integers such that the sum of equals . However, in the netizens’ kingdom, the currency system may be imperfect, meaning there may exist an amount that cannot be represented by the system. For example, in the currency system , , the amounts cannot be represented.
Two currency systems and are equivalent if and only if, for any non-negative integer , either can be represented by both systems, or cannot be represented by either of them.
Now the netizens plan to simplify the currency system. They want to find a currency system such that is equivalent to the original currency system , and is as small as possible. They hope you can help complete this difficult task: find the minimum .
Input Format
The first line of the input file contains an integer , the number of test cases.
Then test cases are given in the following format. The first line of each test case contains a positive integer . The next line contains positive integers separated by spaces.
Output Format
The output file contains lines. For each test case, output one positive integer per line, representing the minimum among all currency systems that are equivalent to .
2
4
3 19 10 6
5
11 29 13 19 17
2
5
Hint
In the first test case, the currency system is equivalent to the given currency system . It can be verified that there is no equivalent currency system with , so the answer is . In the second test case, it can be verified that there is no equivalent currency system with , so the answer is .
【Constraints】

For of the testdata, , and .
Translated by ChatGPT 5