-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path378QAQ and Mocha's Array
90 lines (87 loc) · 1.83 KB
/
378QAQ and Mocha's Array
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
int gcd(int a, int b)
{
if (b == 0)
{
return a;
}
else return gcd(b,a%b);
}
long long int lcm(int a, int b)
{
return a * 1ll * b / gcd(a, b);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
vector<int>v(n);
int jedna = 0;
multiset<int>s;
for(int i=0;i<n;i++)
{
cin >> v[i];
if (v[i] == 1)
{
jedna++;
}
}
if (jedna > 0)
{
cout << "YES" << '\n';
}
else
{
int mini = *min_element(v.begin(), v.end());
vector<int>nd;
for(int i=0;i<n;i++)
{
int teraz = v[i];
if (teraz % mini != 0)
{
nd.push_back(teraz);
}
}
int siz = nd.size();
int flag = 0;
long long int g = 0;
for (int i = 0; i < siz; i++)g = gcd(g, nd[i]);
if (flag == 0)
{
int vys = 0;
for (int i = 0; i < n; i++)
{
if (g%v[i] == 0)
{
vys = 1;
}
}
if (vys == 1)
{
cout << "YES" << '\n';
}
else
{
cout << "NO" << '\n';
}
}
else
{
cout << "NO" << '\n';
}
}
}
return 0;
///std::cout << "Hello World!\n";
}