暴力思想就是n^2遍历,一看范围10^5铁TLE
gcd != 1代表着什么??
有相同因子!
想到这思路就很清晰了,找什么?就是找有没有除1外的相同因子
一看数的范围,可以数组模拟,也可以用哈希表unordered_map,这个范围大的时候用还行
还有个小细节就是对当前值是不是1要处理,只看因子存在不看具体是哪个因子,会出现2,1也认为是不独立的情况
// Problem: 数组划分
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/47266/C
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// Date: 2024-03-14 19:00:38
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
#define endl '\n'
#define int int64_t
using namespace std;
int afac[1000005];
void solve() {
int n; cin >> n;
for (int i = 1,t; i <= n; ++i) {
cin >> t;
for (int j = 1; j * j <= t; ++j) {
if (t % j == 0) {
afac[j]++;
afac[t / j]++;
}
}
}
for (int i = 1,t; i <= n; ++i) {
cin >> t;
for (int j = 1; j * j <= t; ++j) {
if (t % j == 0) {
if ((j != 1 && afac[j]) || (t / j != 1 && afac[t / j])) {
cout << "No\n";
return;
}
}
}
}
cout << "Yes\n";
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}