https://www.luogu.com.cn/problem/P1036
简单的选组合数加素数打表,5分钟搞定!
#include<iostream>
using namespace std;
bool test[100000] = {0};
int su[100000] = {0};
int num = 0;
void da() {
for(int i = 2; i <= 100000; i++) {
if(!test[i]) {
su[num++] = i;
for(int j = i + i; j<=100000; j+=i) {
test[j] = 1;
}
}
}
}
int n,m;
int P[100] = {0};
int P_temp[100] = {0};
int ans_num = 1;
int countt = 0;
void generate(int index) {
if(ans_num == m+1) {
int ans = 0;
for(int i = 1; i < ans_num; i++) {
ans += P_temp[i];
// printf("%d ",P_temp[i]);
}
// printf("\n");
if(!test[ans]) countt++;
return;
}
for(int i = index; i <= n; i++) {
P_temp[ans_num++] = P[i];
generate(i+1);
ans_num--;
}
}
int main() {
da();
scanf("%d%d",&n,&m);
for(int i = 1; i <= n; i++) {
scanf("%d",&P[i]);
}
generate(1);
printf("%d",countt);
}