#P5771. [JSOI2016] 反质数序列

    ID: 6529 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>2016各省省选江苏

[JSOI2016] 反质数序列

Problem Description

For a sequence X:{x1,x2,...,xL}X:\{x_1,x_2,...,x_L\} of length L≥2L \ge 2, if for any 1≤i<j≤L1 \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, N≤10N \le 10.

For 40%40\% of the testdata, N≤150N \le 150.

For 80%80\% of the testdata, N≤1000N \le 1000.

For 100%100\% of the testdata, 2≤N≤30002 \le N \le 3000, 1≤ai≤1051 \le a_i \le 10^5.

Translated by ChatGPT 5