-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathC.cpp
54 lines (52 loc) · 987 Bytes
/
C.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
#include <bits/stdc++.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<ctype.h>
#define lli long long int
#define mod 1000000007
#define pi 3.141592653589793238
using namespace std;
lli gcd(lli a, lli b)
{ if(b==0)
return a;
return gcd(b,a%b);
}
int main()
{ int t;
cin>>t;
//t=1;
while(t--)
{ int n;
cin>>n;
lli a[n],temp[n],min,flag=0;
for(int i=0;i<n;i++)
{ cin>>a[i];
temp[i]=a[i];
}
sort(temp,temp+n);
min=temp[0];
/*for(int i=0;i<n;i++)
cout<<temp[i]<<" ";
cout<<endl; */
for(int i=0;i<n;i++)
{
if(a[i]==temp[i])
continue;
else
{ if(a[i]%min==0)
{
continue;
}
else
{flag=1;break;}
}
}
if(flag==1)
cout<<"NO\n";
else
cout<<"YES\n";
}
return 0;
}