forked from leocamello/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
61 lines (50 loc) · 856 Bytes
/
main.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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int GDC(int a, int b) {
int c = max(a, b) % min(a, b);
if (c == 0)
return min(a, b);
else
return GDC(min(a, b), c);
}
bool checkVector(const vector<int>& v) {
if (v.size() == 1)
return false;
int next = v[0];
for (int i = 1; i < v.size(); i++) {
next = GDC(next, v[i]);
if (next == 1)
return true;
}
return false;
}
int main() {
int T;
cin >> T;
while (T--) {
int N;
cin >> N;
vector<int> v(N);
bool numberOneExists = false;
for (int i = 0; i < N; i++) {
cin >> v[i];
if (v[i] == 1) {
numberOneExists = true;
}
}
if (numberOneExists) {
cout << "YES" << endl;
}
else {
if (checkVector(v))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
return 0;
}