#SP0000220. Dãy tốt dài nhất (Good Sequences)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Dãy tốt dài nhất (Good Sequences)
Good Sequences
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Squirrel Liss has distinct positive integers in strictly increasing order, . You may select a subsequence, skipping some values but keeping the order.
The selected sequence is good if the greatest common divisor of every adjacent pair is greater than . A single-element sequence is valid because it contains no adjacent pair. Find the maximum possible length of a good sequence.
Input
The first line contains . The second line contains the integers in strictly increasing order.
Output
Print a single integer: the maximum length of a subsequence whose every adjacent pair has greatest common divisor greater than .
Subtasks
-
Subtask 1 (20 points): ; .
-
Subtask 2 (30 points): ; .
-
Subtask 3 (50 points): ; .
Examples
Input
5
2 3 4 6 9
Output
4
Explanation
Choose , a sequence of length . Its adjacent gcd values are , , and , all greater than . A length- subsequence would have to contain every input element, but its first adjacent pair has gcd . Therefore no length- good subsequence exists and the maximum length is .