-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP1036.cpp
47 lines (47 loc) · 964 Bytes
/
P1036.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <vector>
using namespace std;
bool Is_prim(int num)
{
if (num == 0 && num == 1)
return false;
if (num == 2)
return true;
for (int i = 2; i < num; i++)
if (num % i == 0)
return false;
return true;
}
int main()
{
int n, k, ans = 0;
cin >> n >> k;
vector<int> nums;
for (int i = 0; i < n; i++)
{
int temp;
cin >> temp;
nums.push_back(temp);
}
int len = nums.size(), limit = 1 << len;
vector<vector<int>> res(limit);
for (int i = 0; i < limit; i++)
{
for (int j = 0; j < n; j++)
{
if ((i >> j) & 1)
res[i].push_back(nums[j]);
}
}
for (auto &x : res)
if (x.size() == k)
{
int sum = 0;
for (auto &y : x)
sum += y;
if (Is_prim(sum))
ans++;
}
cout << ans;
return 0;
}