Two methods of prime sieve

Source: Internet
Author: User

#include <iostream>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace Std;
const int maxn=10005;
BOOL VIS[MAXN];
int PRIME[MAXN];
void Make_prime ()//general linear Sieve, there will be repeated sieve, each time the sieve off is a multiple of prime number
{
memset (vis,true,sizeof (VIS));
Vis[0]=vis[1]=false;
int tot=0;
for (int i=2;i<maxn;i++)
{
if (Vis[i])//indicates that I is a prime number
{
Prime[++tot]=i;
for (int j=i*i;j<maxn;j+=i)//will be able to divide this number of sieves off
Vis[j]=false;
}
}
}
void Euler_prime ()//fast linear sieve, each time the sieve off is i* (less than its minimum factor) of composite
{
memset (vis,true,sizeof (VIS));
int tot=0;
for (int i=2;i<maxn;i++)
{
if (vis[i]) prime[tot++]=i;
for (int j=0;j<tot&&prime[j]*i<maxn;j++)//Whether it is a prime number, this step will be
{
Vis[i*prime[j]]=false;
if (i%prime[j]==0) break;//key
}
}
}
int main ()
{
return 0;
}

Two methods of prime sieve

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.