Created
January 24, 2017 10:17
-
-
Save Ruanxingzhi/26e11dc852ed8e1c2dc1e7e8b6f5c073 to your computer and use it in GitHub Desktop.
线性筛质数。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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