#P15621. [ICPC 2022 Jakarta R] Doubled GCD
[ICPC 2022 Jakarta R] Doubled GCD
题目描述
There are cards in a deck, numbered from to , where card has a positive integer written on it.
You are to perform moves with the cards. In each move, you select two cards of your choice from the deck. Let and be the integers written on the selected cards, respectively. Remove both selected cards, and insert a new card into the deck with written on it, where is the greatest common divisor of and . Note that with this one move, there will be one fewer card in the deck (as you remove two cards and insert one new card).
After all moves have been performed, there will be exactly one card remaining. Your goal is to maximize the integer written on the last card; output this integer.
输入格式
Input begins with an integer () representing the number of cards. The next line contains integers () representing the number written on card .
输出格式
Output an integer in a single line representing the maximum possible integer written on the last card.
3
2 4 6
8
3
3 5 7
2
4
9 9 9 9
36
5
10 100 1000 10000 100000
160
提示
Explanation for the sample input/output #1
To get the maximum possible integer on the last card, you have to select card and card on the first move with and . Remove both selected cards, and insert a new card with written on it. For the second move, there are two cards remaining with an integer written on each card. Select those cards with and . Remove both selected cards, and insert a new card with written on it. The last card has an integer written on it, and it is the maximum possible integer in this example.
Explanation for the sample input/output #2
Regardless of your choice in each move, the answer will always be .