Skip to content

Instantly share code, notes, and snippets.

@Ruanxingzhi
Created January 24, 2017 10:17
Show Gist options
  • Select an option

  • Save Ruanxingzhi/26e11dc852ed8e1c2dc1e7e8b6f5c073 to your computer and use it in GitHub Desktop.

Select an option

Save Ruanxingzhi/26e11dc852ed8e1c2dc1e7e8b6f5c073 to your computer and use it in GitHub Desktop.
线性筛质数。
#include <cstdio>
#include <cstdlib>
bool vis[100005]={0};
int prime[100005]={0},to=0;
void init()
{
int i,j;
for(i=2; i<100005; i++)
{
if(!vis[i])
prime[to++]=i;
for(j=0;j<to && i*prime[j]<100005;j++)
{
vis[i*prime[j]]=1;
if(i%prime[j] == 0) break;
}
}
}
int main(void)
{
int i;
init();
for(i=0;i<to;i++)
printf("%d\n",prime[i]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment