https://www.luogu.com.cn/problem/P1036
#include <iostream>
#include <map>
#include <string.h>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <set>
#include <math.h>
#include <stack>
using namespace std;
typedef long long LL;
const int N = 28;
int num[N];
int select_size;
int ans;
int num_size;
bool is_prime(int d) {
int p = sqrt(d + 0.5);
for (int i = 2; i <= p; i++) {
if (d % i == 0) {
return false;
}
}
return true;
}
void dfs(int pos, int cur_se_size, int sum) {
if (cur_se_size > select_size || pos > num_size) {
return;
}
if (cur_se_size == select_size && is_prime(sum)) {
ans++;
return;
}
dfs(pos + 1, cur_se_size + 1, sum + num[pos]);
dfs(pos + 1, cur_se_size, sum);
}
int main() {
std::ios::sync_with_stdio(false);
cin >> num_size >> select_size;
for (int i = 0; i < num_size; i++) {
cin >> num[i];
}
ans = 0;
dfs(0, 0, 0);
cout << ans << endl;
return 0;
}