PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000167. Ước chung lớn nhất của một cặp (Common Divisors)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Ước chung lớn nhất của một cặp (Common Divisors)

Common Divisors

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

Given an array of nn positive integers x1,…,xnx_1,\ldots,x_n, choose two distinct indices i<ji<j maximizing gcd⁡(xi,xj)\gcd(x_i,x_j). Print the maximum GCD value, not the indices. Equal values at different indices are allowed.

Input

The first line contains nn. The second line contains nn positive integers xix_i.

Output

Print the largest possible GCD of two elements at distinct indices.

Subtasks

  • Subtask 1 (20 points): 2≤n≤1002 \le n \le 100; 1≤xi≤1031 \le x_i \le 10^3.
  • Subtask 2 (30 points): 2≤n≤1042 \le n \le 10^4; 1≤xi≤1051 \le x_i \le 10^5.
  • Subtask 3 (50 points): 2≤n≤2⋅1052 \le n \le 2\cdot 10^5; 1≤xi≤1061 \le x_i \le 10^6.

Examples

Input

5
3 14 15 7 9

Output

7

Explanation

The pair 1414 and 77 yields gcd⁡(14,7)=7\gcd(14,7)=7. No other pair has a larger GCD.