话说来“世间到处都充满着神奇的色彩”。
这份代码我改来改去的,本来只是思路类似于题解,而现在连程序改得马上都要和题解一样了,但仍旧是 12 分,而且还一直在变换,一会 TLE+WA,一会 TLE+WA+RE,一会 MLE+RE 等等情况。
但奇怪(离奇)的是,这份代码在另外一个平台 hydro.ac 上提交,却此次 100.Accepted,所以遇到此情况需要大佬求助,多谢!
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsinged long long
#define il inline
#define ii int
const int MOD = 998244353;
const int MAXN = 100000001, MAXK = 500005, MAXM = 6000000;
ii p[MAXM]; // 存质数。
bool bl[MAXN]; // 判断是否不为质数。
void solving(){
p[1] = 2;
bl[1] = 0;
ii cnt = 1;
for(ii i = 2; i < 100000000; i++){
if(!bl[i]) p[++cnt] = i;
for(ii j = 1; (ll)i * p[j] <= 100000000 && j <= cnt; j++){
bl[i * p[j]] = 1;
if(i % p[j] == 0) break;
}
}
}
template <typename T> void reading(T &x){ // 优化读入操作,可减短程序运行时长。
x = 0; char c = getchar(); long long f = 1;
for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x = x * f; // 返回优化读入过后的输入数值。
}
template <typename T> void writing(T x){ // 优化输出操作,可减短程序运行时长。
if(x < 0){ x = -x; putchar('-');}
if(x > 9) write(x / 10);
putchar(x % 10 + '0'); // 返回优化输出过后的最终运算数值。
}
signed main(){
// freopen("C.in", "r", stdin);
// freopen("C.out", "r", stdout);
solving();
ios::sync_with_stdio(false);
ii t;
cin >> t;
while(t--){
ii n;
cin >> n;
ii a[n];
cin >> a[1];
ii gcd = a[1];
for(ii i = 2; i <= n; i++){
cin >> a[i];
gcd = __gcd(gcd, a[i]);
}
if(n == 2) cout << "Yes" << '\n';
else if(gcd == 1){
bool br[MAXN];
for(ii i = 0; i < 100000001; i++) br[i] = 0;
bool f = 1;
for(ii i = 1; i <= n; i++){
for(ii j = 2; p[j] * p[j] <= a[i]; j++){
if(a[i] % p[j] == 0){
if(br[p[j]] == 1){
f = 0;
break;
}
while(a[i] % p[j] == 0){
a[i] /= p[j];
}
br[p[j]] = 1;
}
}
if(a[i] != 1){
if(br[a[i]] == 1){
f = 0;
} else{
br[a[i]] = 1;
}
}
if(f == 0){
cout << "No" << '\n';
break;
}
} if(f == 1) cout << "Yes" << '\n';
} else cout << "No" << '\n';
}
return 0;
}