cin >> n; vector<int> a; for (int i = 1, x; i <= n; ++i) cin >> x, vis[x] = 1; n = 100000; for (int i = 1; i <= n; ++i) { for (int j = i; j <= n; j += i) vis[i] |= vis[j]; if (vis[i]) a.push_back(i); } sort(a.begin(), a.end(), greater<int>()); n = *max_element(a.begin(), a.end()); init_isp(n); stack<int> S; ll ans = 1; for (auto x : a) { int res = 0; for (auto d : D[x]) res += mu[d] * cnt[d]; while (!S.empty() && res) { int y = S.top(); S.pop(); for (auto d : D[y]) { if (x % d == 0) res -= mu[d]; --cnt[d]; } if (gcd(x, y) == 1) ans = max(ans, 1ll * x * y); } for (auto d : D[x]) ++cnt[d]; S.push(x); } cout << ans << "\n"; return0; }
#include<iostream> // 双 log #include<vector> #define maxn 100010 #define ll long long usingnamespacestd;
int pri[maxn], cnt, mu[maxn]; bool isp[maxn]; voidinit_isp(int n){ mu[1] = 1; for (int i = 2; i <= n; ++i) { if (!isp[i]) pri[++cnt] = i, mu[i] = -1; for (int j = 1; j <= cnt && i * pri[j] <= n; ++j) { isp[i * pri[j]] = 1; if (i % pri[j] == 0) break; mu[i * pri[j]] = -mu[i]; } } }
int n, a[maxn];
vector<int> A[maxn]; bool vis[maxn]; intcheck(ll x){ ll ans = 0; for (int i = 1; i <= n; ++i) { if (!vis[i] || !mu[i]) continue; int m = A[i].size(); ll res = 0; for (int j = 0, k = m - 1; j < m; ++j) { while (k > 0 && 1ll * A[i][k - 1] * A[i][j] >= x) --k; if (1ll * A[i][k] * A[i][j] >= x) res += m - k; } ans += mu[i] * res; } return ans > 0 ; }
cin >> n; for (int i = 1, x; i <= n; ++i) cin >> x, vis[x] = 1; n = 100000; init_isp(n); for (int i = 1; i <= n; ++i) for (int j = i; j <= n; j += i) vis[i] |= vis[j]; for (int i = 1; i <= n; ++i) for (int j = i; j <= n; j += i) if (vis[j]) A[i].push_back(j); ll l = 1, r = 1e10, mid, ans; while (l <= r) { mid = l + r >> 1; if (check(mid)) ans = mid, l = mid + 1; else r = mid - 1; } cout << ans << "\n"; return0; }