Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #define MAX 1000
- int main()
- {
- int prime[100001];
- int i,j;
- for(i=3; i<=MAX; i+=2)
- {
- prime[i]=1;
- }
- prime[2]=1;
- for(i=4; i<=MAX; i+=2)
- {
- prime[i]=0;
- }
- for(j=3; j<=sqrt(MAX); j+=2)
- {
- if(prime[j]==1)
- {
- i=2;
- while(1)
- {
- if(i*j>MAX)
- {
- break;
- }
- else if(prime[i*j]==1)
- {
- prime[i*j]=0;
- }
- i++;
- }
- }
- }
- for(i=2; i<=MAX; i++)
- {
- if(prime[i]==1)
- {
- printf("%d ",i);
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment