-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patht22.cpp
53 lines (49 loc) · 943 Bytes
/
t22.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
#include <bits/stdc++.h>
using namespace std;
bool prime(int x)
{
for (int i = 2; i <= sqrt(x); i++)
if (x % i == 0)
return false;
return true;
}
int check[101] = {0};
int all_prime()
{
for (int i = 2; i < 101; i++)
if (prime(i))
check[i] = 1;
}
int main()
{
all_prime();
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
if (a[0] != 1)
cout << "-1\n";
else
{
bool flag = 0;
for (int i = 0; i < n; i++)
{
if (check[a[i]] == 1)
{
cout << a[i] << "\n";
flag = 1;
break;
}
}
if (!flag)
cout << "-1\n";
}
}
return 0;
}