#SP0000239. Số sinh chung (Common Generator)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Số sinh chung (Common Generator)
Common Generator
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
For integers , is called a generator of if it can be turned into by zero or more operations:
- Choose a divisor of the current value .
- Replace by .
For example, generates via (choose ) and (choose ).
Given pairwise distinct integers , each at least , find an integer that generates every , or print -1 if none exists. Any valid generator is accepted.
Input
- The first line contains integer .
- The second line contains pairwise distinct integers .
Output
Print any integer generating every array element, or -1 if no such integer exists.
Subtasks
-
Subtask 1 (20 points): ; for every ; the elements are pairwise distinct.
-
Subtask 2 (30 points): ; for every ; the elements are pairwise distinct.
-
Subtask 3 (50 points): ; for every ; the elements are pairwise distinct.
Examples
Input
3
8 9 10
Output
2
Explanation
For the array , choose . The sequences are (add , then ), (add , , then ), and (add at every step). Each increment is a divisor of the current integer and is at least . Hence is a common generator.