-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1975B.cpp
More file actions
46 lines (43 loc) · 935 Bytes
/
1975B.cpp
File metadata and controls
46 lines (43 loc) · 935 Bytes
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
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
vector<long long> arr;
rep(i, n)
{
long long x;
cin >> x;
arr.push_back(x);
}
sort(arr.begin(),arr.end());
if(arr[0]==1) {
cout<<"YES"<<endl;
continue;
}
set<int> ind;
long long next=-1;
rep(i,n) {
if(arr[i]%arr[0]==0) ind.insert(i);
if(next==-1 && arr[i]%arr[0]!=0) next=arr[i];
if(next!=-1) {
if(arr[i]%next==0) ind.insert(i);
}
}
int sum=0;
for(int i:ind) {
sum+=i;
}
if(sum==((n*(n-1))/2)) {
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}
}