#P5771. [JSOI2016] 反质数序列

[JSOI2016] 反质数序列

Description

For a sequence X:{x1,x2,...,xL}X:\{x_1,x_2,...,x_L\} of length L2L \ge 2, if for any 1i<jL1 \le i < j \le L, xi+xjx_i + x_j is not a prime number, then JYY considers the sequence XX to be an “anti-prime sequence”.

JYY has a sequence A:{a1,a2,...,aN}A:\{a_1,a_2,...,a_N\} of length NN. He wants to choose a subsequence with as many elements as possible such that this subsequence is an anti-prime sequence.

Input Format

The first line contains a positive integer NN.

The next line contains NN positive integers, describing a1,a2,...,aNa_1,a_2,...,a_N in order.

Output Format

Output one integer in a single line, representing the length of the longest anti-prime subsequence. The input guarantees that an anti-prime subsequence exists.

6
1 2 2 3 4 10

4

Hint

For 10%10\% of the testdata, N10N \le 10.

For 40%40\% of the testdata, N150N \le 150.

For 80%80\% of the testdata, N1000N \le 1000.

For 100%100\% of the testdata, 2N30002 \le N \le 3000, 1ai1051 \le a_i \le 10^5.

Translated by ChatGPT 5