PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000160. Đoạn con có GCD nguyên tố (Prime Dominion)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đoạn con có GCD nguyên tố (Prime Dominion)
Prime Dominion
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given a positive-integer array , a contiguous subarray is valid if its GCD is a prime number. Determine the maximum length of a valid subarray. Single-element subarrays are allowed. Print -1 when no valid subarray exists.
Input
The first line contains . The next line contains the array values.
Output
Print the length of the longest valid subarray, or -1 if none exists.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
5
2 4 6 9 3
Output
3
Explanation
The contiguous subarray at positions through has GCD , a prime, and has length . No longer subarray has prime GCD.