CF665D.Simple Subset

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A tuple of positive integers {_x_1, _x_2, ..., x__k} is called simple if for all pairs of positive integers (i,  j) (1  ≤ i  <  j ≤ k), x__i  +  x__j is a prime.

You are given an array a with n positive integers _a_1,  _a_2,  ...,  a__n (not necessary distinct). You want to find a simple subset of the array a with the maximum size.

A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.

Let's define a subset of the array a as a tuple that can be obtained from a by removing some (possibly all) elements of it.

由正整数构成的元组 {x1, x2, …, xk}\{x_1,\,x_2,\,\dots,\,x_k\} 被称为简单元组,当且仅当对所有满足 1≤i<j≤k1 \le i < j \le k 的正整数对 (i, j)(i,\,j),其和 xi+xjx_i + x_j 均为素数。

给定一个包含 nn 个正整数 a1, a2, …, ana_1,\,a_2,\,\dots,\,a_n(元素未必互异)的数组 aa。你需要在数组 aa 中找出一个大小最大的简单子集。

素数(或质数)是指大于 11 的自然数,且除了 11 和它自身之外没有其他正因数。

我们定义数组 aa 的一个子集为:从 aa 中删去若干(可能全部)元素后所得到的元组。

输入格式

The first line contains integer n (1 ≤ n ≤ 1000) — the number of integers in the array a.

The second line contains n integers a__i (1 ≤ a__i ≤ 106) — the elements of the array a.

第一行包含一个整数 nn(1≤n≤10001 \leq n \leq 1000)—— 数组 aa 中的整数个数。

第二行包含 nn 个整数 aia_i(1≤ai≤1061 \leq a_i \leq 10^6)—— 数组 aa 的元素。

输出格式

On the first line print integer m — the maximum possible size of simple subset of a.

On the second line print m integers b__l — the elements of the simple subset of the array a with the maximum size.

If there is more than one solution you can print any of them. You can print the elements of the subset in any order.

第一行输出整数 mm —— 数组 aa 的简单子集的最大可能大小。

第二行输出 mm 个整数 blb_l —— 数组 aa 的一个最大大小的简单子集的元素。

若存在多个解,可输出其中任意一个。子集元素的输出顺序可以任意。

输入输出样例

  • 输入#1

    2
    2 3

    输出#1

    2
    3 2
  • 输入#2

    2
    2 2

    输出#2

    1
    2
  • 输入#3

    3
    2 1 1

    输出#3

    3
    1 1 2
  • 输入#4

    2
    83 14

    输出#4

    2
    14 83

输入解题思路,AI测评打分。不知道怎么写?

首页