问题 - 1401C - 代码强制 (codeforces.com)
![](https://i-blog.csdnimg.cn/blog_migrate/77f7eab8397ce6f90e017e6845cf2d53.png)
![](https://i-blog.csdnimg.cn/blog_migrate/3e25fc1dd3b40f82f64d29f4de7023ab.png)
给定一组数,每次可以进行的操作是,如果两个数的gcd等于这组数中的最小值minn,就可以交换,问是否可以只通过这种操作使得这这组数变成单调不下降的
对于minn 的倍数,我们可以进行多次操作,一定能使得在这些位置上的数满足条件,关键就是看不是minn倍数的数在不在它应该在的位置
#include <iostream>
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <unordered_map>
#include <queue>
#include <algorithm>
#define x first
#define y second
#define pb emplace_back
#define fu(i,a,b) for(int i=a;i<=b;i ++ )
#define fd(i,a,b) for(int i=a;i>=b;i -- )
#define endl '\n'
#define ms(x,y) memset(x,y,sizeof x)
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
typedef long long LL;
typedef vector<vector<LL>> VVL;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef pair<PII,int> PIII;
typedef pair<double,double> PDD;
typedef pair<double,int> PDI;
typedef pair<char,int> PCI;
typedef pair<string,int> PSI;
typedef pair<int,string> PIS;
typedef pair<int,char> PIC;
typedef pair<LL,LL> PLL;
typedef __int128 i128;
typedef unsigned long long ULL;
const int N = 500+ 10,M = N * N /2 ,INF = 0x3f3f3f3f ;
const int mod = 1e9;
const double eps = 1e-8;
inline void solve()
{
int n,minn=INF;cin >> n;
VI a(n);
fu(i,0,n-1) cin >> a[i],minn= min(minn,a[i]);
auto b =a;
sort(b.begin(),b.end());
for(auto & t : a ) if(t % minn ==0 ) t =0;
for(auto & t : b )if(t % minn == 0 ) t=0;
cout << (a == b ? "YES" : "NO") <<endl;
}
signed main()
{
// freopen("1.txt","w",stdout);
ios
// cout << fixed<<setprecision(3);
int t=1;
cin>>t;
int now = 1;
while(t -- )
{
// cout<<"Case ";
// cout<<"Scenario #";
// cout<< now ++ <<": ";
// cout<< now ++ <<": \n";
solve();
}
return 0;
}