Amusement Park Rides

면접 대비

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

요약
각 놀이기구가 a_i의 배수 분에 운행할 때, 서로 다른 분에 모든 기구를 한 번씩 타는 가장 이른 완료 시각을 구한다.
난이도

보통10점 중 5점

유형
그리디, 정렬, 배열
정답자
아직 제출이 없습니다

문제

Ivan, Dmitrii, and Pjotr are celebrating Ivan’s birthday at an amusement park with nn attractions. The ii-th attraction operates at minutes a_i,2a_i,3a_i,…a\_i , 2a\_i , 3a\_i , \dots (i.e., every a_ia\_i minutes).

Each minute, the friends can either ride exactly one available attraction together or wait. Since the rides are very short, they can board another attraction the next minute. They may ride the attractions in any order.

They want to experience each ride exactly once before heading off to enjoy the birthday cake. What is the earliest time by which they can finish all nn attractions?

입력

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤20001 ≤ t ≤ 2000) — the number of test cases. The descriptions of the tt test cases follow.

The first line contains an integer nn (1≤n≤20001 ≤ n ≤ 2000) — the number of attractions.

The second line contains nn integers a_1,a_2,…,a_na\_1, a\_2, \dots , a\_n (1≤a_i≤1091 ≤ a\_i ≤ 10^9 ) — the values determining when the various attractions operate.

It is guaranteed that the sum of nn over all test cases does not exceed 20002000.

출력

For each test case, print the earliest time the three friends can finish all nn attractions.

예제1

  1. 예제 1

    입력
    3
    4
    1 2 3 4
    4
    1 1 1 1
    6
    1 2 1 2 2 2
    
    예상 출력
    4
    4
    8