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;
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-04 15:36
点赞 评论 收藏
分享
见见123:简历没有啥问题,是这个社会有问题。因为你刚毕业,没有工作经历,现在企业都不要没有工作经历的。社会病了。
点赞 评论 收藏
分享
05-21 15:47
门头沟学院 Java
浪漫主义的虹夏:项目有亮点吗,第一个不是纯玩具项目吗,项目亮点里类似ThreadLocal,Redis储存说难听点是花几十分钟绝大部分人都能学会,第二个轮子项目也没体现出设计和技术,想实习先沉淀,好高骛远的自嗨只会害了自己
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 13:15
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务