PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000045. Sherlock và UCLN của một dãy con (Sherlock and GCD)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Sherlock và UCLN của một dãy con (Sherlock and GCD)
Sherlock and GCD
Source: HackerRank
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array of positive integers, determine whether there exists a nonempty subset with no repeated values whose GCD is . The selected elements need not be consecutive.
Input
First line: . Second line: positive integers .
Output
Print YES if such a subsequence exists, otherwise NO.
Subtasks
- Subtask 1 (20 points): ;
- Subtask 2 (30 points): ;
- Subtask 3 (50 points): ;
Examples
Input
3
2 4 3
Output
YES
Explanation
The subsequence has two elements with GCD , so the answer is YES.