#GL0000143. Đưa ƯCLN về một (Make It One)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đưa ƯCLN về một (Make It One)
Make It One
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given positive integers . Select a nonempty subset of distinct indices; the chosen positions need not be consecutive and each index is used at most once.
The score of the subset is the GCD of its values. Find the minimum subset size with score equal to , or print -1 if no such subset exists. Equal values at different indices are still distinct elements.
Input
The first line contains ; the second contains positive integers .
Output
Print the minimum number of elements in a subset with GCD , or -1 if none exists.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
3
10 6 15
Output
3
Explanation
The GCD of all three values is , while pairwise GCDs are , , and . No one- or two-element subset works, so all three elements are needed.