[51NOD1181]质数中的质数(质数筛法)(欧拉筛)

时间:2023-03-08 17:38:42
[51NOD1181]质数中的质数(质数筛法)(欧拉筛)

题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1181

思路:欧拉筛出所有素数和一个数的判定,找到大于n的最小质数序号p,并且判断p是不是质数,输出这个数。

     /*
━━━━━┒ギリギリ♂ eye!
┓┏┓┏┓┃キリキリ♂ mind!
┛┗┛┗┛┃\○/
┓┏┓┏┓┃ /
┛┗┛┗┛┃ノ)
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┃┃┃┃┃┃
┻┻┻┻┻┻
*/
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%lld", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f7f, sizeof(a))
#define lrt rt << 1
#define rrt rt << 1 | 1
#define pi 3.14159265359
#define RT return
#define lowbit(x) x & (-x)
#define onenum(x) __builtin_popcount(x)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<LL, LL> pll;
typedef map<string, int> msi;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb; const int maxn = ;
int n, pcnt;
bool isprime[maxn];
int prime[maxn]; int main() {
// FRead();
Cls(prime); Clr(isprime, true); pcnt = ;
For(i, , maxn) {
if(isprime[i]) prime[++pcnt] = i;
For(j, , pcnt+) {
if(i * prime[j] > maxn) break;
isprime[i*prime[j]] = ;
if(i % prime[j] == ) break;
}
}
while(~Rint(n)) {
int p = ;
while(prime[p] < n) p++;
while() {
if(isprime[p]) break;
p++;
}
printf("%d\n", prime[p]);
}
RT ;
}