- Time: 2016-04-27-15:16:14
- Title Number: [2016-04-27][codeforces][665d-simple subset]
- The main idea: Given the n number of set A, ask the subset of the maximum size, so that the sum of 22 of the sub-set is a prime, output and any one such subset
- Analysis:
- At most one 1:
- First take any 3 numbers from a
- If there are at most 1 of these 3 numbers, 1
- By the principle of tolerance, there must be two numbers of the sum is even, and the sum of the even greater than 2 (must not be a prime number), so the answer subset, more than 1 of the numbers can only have two,
- Spread to the whole A, that is, if a is at most 1 1, the subset has a maximum of 2 digits, then the answer is
- The sum of no two numbers is a prime number,
- There is a sum of two numbers that are primes, (even if there are many pairs, only one pair can be output)
- If more than 1, then the answer is
- It's all 1.
- In addition to 1, there is also a number, the number +1 is the prime
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 1E3 + 10;
const int maxp = 1E6*2 + 10;
int isnpri[maxp],a[maxn];
void getpri(){
memset ( isnpri 0 sizeof isnpri
for ( int i = 2 ; I < Maxp + 10 ; ++ i ) {
if(isnpri[i]) continue;
for(int j = i * 2 ; j < maxp; j += i){
isnpri[j] = 1;
}
}
}
int main(){
getpri();
int n,cnt1 = 0;
scanf("%d",&n);
for(int i = 0 ; i < n ; ++i){
scanf("%d",&a[i]);
if(a[i] == 1) ++cnt1;
}
if(cnt1 > 1){
for ( int i = 0 ; I < n ++ i ) {
if ( a [ i != 1 && ! isnpri [ a [ i + 1
printf("%d\n%d",cnt1 + 1,a[i]);
for(int j = 0 ; j < cnt1;++j){
printf(" 1");
}
return 0;
}
}
printf("%d\n",cnt1);
for(int j = 0 ; j < cnt1;++j){
printf("1 ");
}
return 0;
}
for ( int i = 0 ; I < n ++ i ) {
for ( int J = 0 ; J < n ++ j ) {
if ( i != J && ! isnpri [ a [ i + a [ j ]) {
printf("2\n%d %d",a[i] , a[j]);
return 0;
}
}
}
printf("1\n%d",a[0]);
return 0;
}
From for notes (Wiz)
[2016-04-27] [Codeforces] [665d-simple subset]