아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Array

면접 대비

시간 제한3초메모리 제한256 MB

요약
배열을 임의로 재배열해 x = x mod a_i를 반복한 뒤 얻을 수 있는 마지막 값의 최댓값을 구한다.
난이도

보통10점 중 6점

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

문제

You are given an array a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n. Let x_1=a_1x\_1 = a\_1, and x_i=x_i−1 mod a_ix\_i = x\_{i - 1} \bmod a\_i for each ii from 22 to nn.

Suppose that we can rearrange a_1,…,a_na\_1, \ldots, a\_n in any way. What is the largest possible value of x_nx\_n we can obtain?

입력

The first line contains an integer nn --- the size of the array (2≤n≤1052\leq n\leq 10^5).

The second line containing nn integers a_1,…,a_na\_1, \ldots, a\_n (1≤a_i≤1051\leq a\_i\leq 10^5).

출력

Print one integer --- the largest possible value of x_nx\_n.

예제1

  1. 예제 1

    입력
    5
    5 5 10 17 23
    
    예상 출력
    3