D
材料打印
https://ac.nowcoder.com/acm/contest/88455/A
D乱搞做法 题目可转化为求最小的未出现的质数。 容易观察到n<=2e5时,连续的合数不超过100个,即将题目数组a排序后,当a[i]-a[i-1]>100时,答案一定在a[i-1]到a[i]之间,因此从2枚举到a[n-1]+100即可,时间复杂度最坏不超过O(100nlogn),很大程度上跑不满,刚好能过。
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define endl "\n"
#define lowbit(x) x & (-x)
const int N = 1e6 + 10, M = 110, mod = 998244353, inf = 2e9;
typedef pair<int, int> pt;
typedef long long ll;
bool isprime(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0) return 0;
}
return 1;
}
void solve() {
int n;
cin >> n;
vector<int> a(n);
map<int, int> mp;
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
}
sort(a.begin(), a.end());
for (int i = 2; i <= a[n - 1] + 100; i++) {
if (isprime(i) && !mp.count(i)) {
cout << i << endl;
return;
}
}
}
signed main() {
//freopen("title.in", "r", stdin);
//freopen("std.txt", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}