-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1562B.cpp
65 lines (58 loc) · 1.47 KB
/
1562B.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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX = 1e3+2;
inline void Quick_IO() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
vector<bool> isPrime;
vector<int> prime;
int main() {
Quick_IO();
int t;
cin >> t;
isPrime.resize(MAX + 1);
fill(isPrime.begin(), isPrime.end(), true);
prime.push_back(2);
for (int i = 4; i <= MAX; i += 2)
isPrime[i] = false;
for (int i = 3; i <= MAX; i++) {
if (isPrime[i]) prime.push_back(i);
for (int j = i * i; j <= MAX; j += i * 2)
isPrime[j] = false;
}
isPrime[1] = false;
while (t--) {
string n;
int k;
cin >> k >> n;
bool isOne = false;
for (int i = 0; i < k; ++i) {
if(!isPrime[n[i]-'0']){
cout<<1<<'\n';
cout<<n[i]<<'\n';
isOne = true;
break;
}
}
if(!isOne){
for (int i = 0; i < k; ++i) {
bool flag = true;
for (int j = i+1; j < k; ++j) {
int t1 = n[i]-'0', t2 = n[j]-'0';
if(!isPrime[(t1*10+t2)]){
cout<<2<<'\n';
cout<<t1*10+t2<<'\n';
flag = false;
break;
}
}
if(!flag) break;
}
}
}
return 0;
}