-
Notifications
You must be signed in to change notification settings - Fork 0
/
uva10871.cpp
70 lines (58 loc) · 1.26 KB
/
uva10871.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <cstdio>
#include <cmath>
#include <cstring>
const int MAXN = 10010;
bool u[MAXN];
int su[MAXN];
int s[MAXN];
int num;
void sieve_prime(int n) {
num = 1;
memset(u, true, sizeof(u));
for(int i = 2; i <= n; ++i) {
if(u[i]) su[num++] = i;
for(int j = 1; j < num; ++j) {
if(i*su[j] > n) break;
u[i*su[j]] = false;
if(i % su[j] == 0) break;
}
}
}
bool pri(int n) {
if(n < 10010) return u[n];
for(int i = 1; i < num; ++i)
if(n % su[i] ==0)
return false;
return true;
}
int main() {
int n = 10010;
sieve_prime(n);
int ncase;
scanf("%d", &ncase);
s[0] = 0;
while(ncase--) {
int tnum;
scanf("%d", &tnum);
for(int i = 1; i <= tnum; ++i) scanf("%d", &s[i]);
for(int i = 1; i <= tnum; ++i) s[i] += s[i-1];
bool ok = false;
for(int d = 2; d <= tnum; ++d) {
for(int i = 1; i <= tnum - d + 1; ++i) {
int v = s[i+d-1] - s[i-1];
if(pri(v)) {
printf("Shortest primed subsequence is length %d:", d);
for(int a = 1; a <= d; ++a) printf(" %d", s[i+a-1]-s[i+a-2]);
printf("\n");
ok = true;
break;
}
}
if(ok) break;
}
if(!ok) {
printf("This sequence is anti-primed.\n");
}
}
return 0;
}