Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 #include <stdio.h>
- 2 #include <stdlib.h>
- 3 #include <math.h>
- 4
- 5
- 6 int main()
- 7 {
- 8
- 9 char *tab;
- 10 int i,j,n;
- 11 int max;
- 12
- 13 scanf("%d", &n);
- 14 max = sqrt(n);
- 15 tab = calloc(n, sizeof(char));
- 16
- 17 for(i = 2; i <=max ; i++)
- 18 {
- 19 if(tab[i] == 0)
- 20 {
- 21 for(j = i + 1; j <= n ; j++)
- 22 {
- 23 if(tab[j] == 1)
- 24 continue;
- 25 if(j % i == 0)
- 26 tab[j] = 1;
- 27
- 28 }
- 29 }
- 30 }
- 31 tab[5] = 0;
- 32 for(i = 0; i <= n; i++)
- 33 {
- 34 if(tab[i] == 0)
- 35 printf("%d\n", i);
- 36
- 37 }
- 38
- 39 return 0;
- 40 }
Add Comment
Please, Sign In to add comment