提交时间:2026-06-06 13:59:51
运行 ID: 41943
#include <iostream> #include <set> #include <vector> using namespace std; using i64 = long long; i64 gcd(i64 x, i64 y) { while (y != 0) { i64 t = x % y; x = y; y = t; } return x; } inline i64 lcm(i64 x, i64 y) { if (x == 0) return y; else if (y == 0) return x; else return x * y / gcd(x, y); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int T; cin >> T; while (T-- > 0) { int n; cin >> n; bool have_1 = false; vector<int> a(n); for (int& x : a) { cin >> x; if (x == 1) have_1 = true; } if (!have_1) { cout << "1\n"; continue; } set<int> vis; for (int i = 0; i < n; ++i) { int cur = 0; for (int j = i; j < n; ++j) { i64 nxt = lcm(cur, a[j]); if (nxt > n * n + 1) break; cur = nxt; vis.insert(cur); } } vis.erase(-1); int lst = 0; bool found = false; for (int x : vis) { if (x - lst > 1) { cout << lst + 1 << '\n'; found = true; break; } lst = x; } if (!found) cout << lst + 1 << '\n'; } cout << flush; return 0; }