【素数】Eratosthenes筛选

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
int main()
{
    /*素数筛选*/
    /*Eratosthenes筛选*/
    /*确定某一个数是素数之后,删除这个数的所有的倍数*/
    int n;
    cin >> n;
    memset(vis, 0, sizeof(vis));
    for(int i = 2; i <= sqrt(n); i++)
        if(!vis[i])
            for(int j = i * i; j <= n; j += i)
                vis[j] = 1;


}

猜你喜欢

转载自www.cnblogs.com/Kohinur/p/9070855.html