Amusement Park Rides
면접 대비시간 제한2초메모리 제한2048 MB
각 놀이기구가 a_i의 배수 분에 운행할 때, 서로 다른 분에 모든 기구를 한 번씩 타는 가장 이른 완료 시각을 구한다.
문제
Ivan, Dmitrii, and Pjotr are celebrating Ivan’s birthday at an amusement park with attractions. The -th attraction operates at minutes (i.e., every 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 attractions?
입력
Each test contains multiple test cases. The first line contains an integer () — the number of test cases. The descriptions of the test cases follow.
The first line contains an integer () — the number of attractions.
The second line contains integers () — the values determining when the various attractions operate.
It is guaranteed that the sum of over all test cases does not exceed .
출력
For each test case, print the earliest time the three friends can finish all attractions.