#SP0000217. Dãy con có tổng nguyên tố (Primed Subsequence)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Dãy con có tổng nguyên tố (Primed Subsequence)
Primed Subsequence
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a sequence of nonnegative integers. A primed subsequence is a contiguous segment containing at least two elements whose sum is prime (a prime is an integer greater than with exactly two positive divisors).
Find a valid segment of minimum length. If several segments have the same minimum length, choose the one with the earliest starting position. If no such segment exists, print the exact prescribed message. Preserve the original order of the chosen elements.
Input
The first line contains the integer . The second line contains nonnegative integers in sequence order.
Output
If a valid segment exists, print one line beginning with the exact phrase Shortest primed subsequence is length x: (replace x by the segment length), followed by a space and the chosen elements separated by spaces. Otherwise, print exactly This sequence is anti-primed..
Subtasks
-
Subtask 1 (20 points): ; for all .
-
Subtask 2 (30 points): ; for all .
-
Subtask 3 (50 points): ; for all .
Examples
Input
5
3 5 6 3 8
Output
Shortest primed subsequence is length 2: 5 6
Explanation
The sequence is . The adjacent pair sums, in order, are (not prime), (prime), (not prime), and (prime). Length is the smallest permitted length. Among the two qualifying pairs, starts earlier, at position rather than position . Hence the displayed segment is .