和题解区都不一样的做法,求 Hack 或者证伪。
code:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cassert>
#include <chrono>
#include <random>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define desktop "C:\\Users\\incra\\Desktop\\"
#define IOS ios :: sync_with_stdio (false),cin.tie (0),cout.tie (0)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> PII;
const int dx[] = {1,0,-1,0},dy[] = {0,-1,0,1};
template <typename T1,typename T2> bool tomax (T1 &x,T2 y) {
if (y > x) return x = y,true;
return false;
}
template <typename T1,typename T2> bool tomin (T1 &x,T2 y) {
if (y < x) return x = y,true;
return false;
}
LL power (LL a,LL b,LL p) {
LL ans = 1;
while (b) {
if (b & 1) ans = ans * a % p;
a = a * a % p;
b >>= 1;
}
return ans;
}
int fastio = (IOS,0);
#define puts(s) cout << s << endl
const int N = 300010,MAX_LOG = 20;
const LL INF = 1e7;
int n;
LL a[N];
int lg[N];
LL f[N][MAX_LOG];
LL gcd (LL a,LL b) {
return !b ? a : gcd (b,a % b);
}
LL lcm (LL a,LL b) {
return a / gcd (a,b) * b;
}
LL query (int l,int r) {
int k = lg[r - l + 1];
return min (lcm (f[l][k],f[r - (1 << k) + 1][k]),INF);
}
int main () {
// freopen ("input.in","r",stdin);
for (int i = 2;i < N;i++) lg[i] = lg[i >> 1] + 1;
int T;
cin >> T;
while (T--) {
cin >> n;
for (int i = 1;i <= n;i++) cin >> a[i],f[i][0] = a[i];
for (int j = 1;j < MAX_LOG;j++) {
for (int i = 1;i + (1 << j - 1) <= n;i++) f[i][j] = min (lcm (f[i][j - 1],f[i + (1 << j - 1)][j - 1]),INF);
}
set <LL> vis;
for (int i = 1;i <= n;i++) {
int j = i;
while (j <= n) {
if (query (i,j) == INF) break;
int l = j,r = n;
while (l < r) {
int mid = l + r + 1 >> 1;
if (query (i,j) == query (i,mid)) l = mid;
else r = mid - 1;
}
vis.insert (query (i,j));
j = l + 1;
}
}
int ans = 1;
while (vis.count (ans)) ans++;
cout << ans << endl;
}
return 0;
}