-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1415.cpp
More file actions
55 lines (53 loc) · 1.02 KB
/
1415.cpp
File metadata and controls
55 lines (53 loc) · 1.02 KB
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
48
49
50
51
52
53
54
55
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define ll long long
const int MAX = 500000 + 1;
bool p[MAX] = {
true,
true,
false,
};
int cnt[10001];
ll dp[2][MAX];
int main() {
int s = 0, M = 0;
for (int i = 2; i < MAX; i++) {
if (p[i]) continue;
for (int j = 2; j * i < MAX; j++) {
p[j * i] = true;
}
}
int n;
scanf("%d", &n);
for (int i = 0, v; i < n; i++) {
scanf("%d", &v);
cnt[v]++;
s += v;
M = max(M, v);
}
bool tog = true;
dp[tog][0] = cnt[0] + 1;
for (int i = 1; i <= M; i++) {
if (!cnt[i]) continue;
tog = !tog;
memset(dp[tog], 0, sizeof(dp[tog]));
for (int j = 0; j <= cnt[i]; j++) {
for (int k = s; k >= i * j; k--) {
if (k - i * j < 0) break;
dp[tog][k] += dp[!tog][k - i * j];
}
}
}
ll R = 0;
for (int i = 2; i <= s; i++) {
if (!p[i]) R += dp[tog][i];
}
printf("%lld\n", R);
}