PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000116. ƯCLN trên bảng (GCD on Blackboard)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
ƯCLN trên bảng (GCD on Blackboard)
GCD on Blackboard
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are positive integers on a blackboard. Choose exactly one position and replace its value with any integer from to , possibly the same value. Find the largest possible GCD of all integers after the replacement.
Input
The first line contains . The second line contains integers .
Output
Print the maximum attainable GCD.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
3
7 6 8
Output
2
Explanation
Replace 7 with 4 to obtain 4, 6, 8, whose GCD is 2. No larger GCD is possible.