You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1018 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int T;
int a[N];
int n;
/*
2
3
1 2 4
5
1 2 3 4 5
*/
bool check() {
//遍历a[1]~a[n]中每个数字
// 当前枚举到的数字是a[i]
// 判断当前数字a[i]是不是其它数的倍数,不需要避开自己,因为自己肯定是自己的倍数
// 找完一圈后发现a[i]是其它数字的倍数返回true
// 找完一圈后发现a[i]不是其它数字的倍数则i++
//如果到了最后一个还没有找到是其它数倍数的数字那么返回false
for (int i = 1; i <= n; i++) {
bool flag = false;//默认a[i]是好用的
for (int j = 1; j <= n; j++) {
if (a[i] % a[j]) { //a[i]不是a[j]的倍数,么a[i]是个废物,后续的a[j]不用继续讨论了
flag = true;//用来标记是中间被打断的也就是不合理的a[i]
break;
}
}
//到达了这里
if (!flag)
return true;
}
return false;
}
int main() {
cin >> T;
while (T--) {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
if (check())
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}