inlineintpower(int x, int y){ int res = 1; while (y) { if (y & 1) res = (LL)res * x % P; x = (LL)x * x % P, y >>= 1; } return res; }
int n, cntp, ans; int a[N], pri[N], ma[N], cnt[N]; bool np[N], wc[N];
inlinevoidget_prime(int lim){ np[1] = true; for (int i = 2; i <= lim; ++i) { if (!np[i]) pri[++cntp] = i; for (int j = 1; j <= cntp && pri[j] * i <= lim; ++j) { np[pri[j] * i] = true; if (i % pri[j] == 0) break; } } }
inlinevoidupdate(int p, int c){ if (c > ma[p]) ma[p] = c, cnt[p] = 1; elseif (c == ma[p]) ++cnt[p]; }
inlinevoiddeco(int x){ for (int i = 1; i <= cntp && pri[i] * pri[i] <= x; ++i) { int p = pri[i]; if (x % p) continue; int c = 0; while (x % p == 0) x /= p, ++c; update(p, c); } if (x > 1) update(x, 1); }
inlineboolcheck(int x){ if (!np[x]) { // bug if (ma[x] == 1 && cnt[x] == 1) returnfalse; returntrue; } for (int i = 1; i <= cntp && pri[i] * pri[i] <= x; ++i) { int p = pri[i]; if (x % p) continue; int c = 0; while (x % p == 0) x /= p, ++c; if (ma[p] == c && cnt[p] == 1) returnfalse; } if (x > 1 && ma[x] == 1 && cnt[x] == 1) returnfalse; // bug returntrue; }
inlinevoidmain(){ cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; sort(a+1, a+n+1), reverse(a+1, a+n+1); get_prime(a[1]); ans = 1; for (int i = 1; i <= n; ++i) { if (ma[a[i]]) deco(a[i] - 1), wc[i] = true; else update(a[i], 1); } for (int i = 1; i <= cntp; ++i) { if (!ma[pri[i]]) continue; ans = (LL)ans * power(pri[i], ma[pri[i]]) % P; } for (int i = 1; i <= n; ++i) { if ((wc[i] && check(a[i] - 1)) || (!wc[i] && check(a[i]))) { ++ans; break; } } cout << ans << '\n'; }
v1.5.2