Guest User

Untitled

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