#include <cstdio>
#include <algorithm>
using namespace std;
int N, K;
int num[20+2];
bool flag[20+2];
int ans[20+2];
int cnt;
bool cmp(int a, int b){
return a<b;
}
bool IsPrime(int n){
if(n<2) return false;
if(n==2 || n==3) return true;
if(n%2==0 || n%3==0) return false;
for(int i=5, d=4; i*i<=n; i+=d^=6){
if(n%i==0) return false;
}
return true;
}
void Array(int n, int p){
if(n>K){
int tmp = 0;
for(int i = 1; i<=K; ++i) tmp+=ans[i];
if(IsPrime(tmp)) ++cnt;
return;
}
for(int i = p; i<N; ++i){
if(!flag[i]){
flag[i] = true;
ans[n] = num[i];
Array(n+1, i);
flag[i] = false;
}
}
}
int main(){
scanf("%d %d", &N, &K);
for(int i = 0; i<N; ++i) scanf("%d", &num[i]);
sort(num, num+N, cmp);
Array(1, 0);
printf("%d\n", cnt);
return 0;
}
CodeVS1008 選數 題解
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.