Files
python/GESP/Level4/GESP202406/2024062902_1.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

52 lines
1018 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}