#P15552. [CCPC 2025 哈尔滨站] k-子集和最大公约数问题
[CCPC 2025 哈尔滨站] k-子集和最大公约数问题
Problem Description
Consider an infinite multiset , whose elements include , and each type of element appears infinitely many times. Based on this, we define a function as follows: for every subset of with size exactly , compute the sum of elements in . Take the greatest common divisor of all such sums, and use it as the value of . Formally,
$$f(k) = \gcd_{S' \subseteq S, |S'| = k} \left( \sum_{x \in S'} x \right)$$For example, for , we have
Now please find the maximum value of , and the smallest that achieves this maximum. In particular, if the maximum value does not exist, report infinite.
Input Format
This problem contains multiple test cases. The first line contains an integer (), representing the number of test cases.
Then each test case is given as follows:
The first line contains an integer (), representing the number of distinct values in .
The second line contains integers (), representing the elements in .
It is guaranteed that the sum of over all test cases does not exceed .
Output Format
For each test case, if has a maximum value, output one line with two integers: the maximum value of , and the smallest that achieves this maximum.
Otherwise output infinite (without quotes).
2
2
3 6
2
2 2
3 1
infinite
2
3
1 4 7
4
4 16 28 34
3 3
6 3
Hint
For the first test case in Sample 1, you can find that no matter what is, .
For the second test case in Sample 1, we have , so grows without bound and the maximum value does not exist.
Translated by ChatGPT 5