Doubled GCD

시간 제한2초메모리 제한1024 MB

요약
카드 두 장 x, y를 2*gcd(x, y)로 바꾸는 연산을 N-1번 해 마지막 카드에 적힌 수를 최대로 만든다.
난이도

어려움10점 중 8점

유형
수학, 정수론, 그리디, 구현
정답자
아직 제출이 없습니다

문제

There are NN cards in a deck, numbered from 11 to NN, where card ii has a positive integer A_iA\_i written on it.

You are to perform N−1N - 1 moves with the cards. In each move, you select two cards of your choice from the deck. Let xx and yy be the integers written on the selected cards, respectively. Remove both selected cards, and insert a new card into the deck with 2⋅gcd⁡(x,y)2 \cdot \gcd(x, y) written on it, where gcd⁡(x,y)\gcd(x, y) is the greatest common divisor of xx and yy. 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 N−1N -1 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 NN (2≤N≤100,0002 ≤ N ≤ 100\\, 000) representing the number of cards. The next line contains NN integers A_iA\_i (1≤A_i≤1091 ≤ A\_i ≤ 10^9) representing the number written on card ii.

출력

Output an integer in a single line representing the maximum possible integer written on the last card.

예제4

  1. 예제 1

    입력
    3
    2 4 6
    
    예상 출력
    8
    
  2. 예제 2

    입력
    3
    3 5 7
    
    예상 출력
    2
    
  3. 예제 3

    입력
    4
    9 9 9 9
    
    예상 출력
    36
    
  4. 예제 4

    입력
    5
    10 100 1000 10000 100000
    
    예상 출력
    160