Advertisement
palmerstone

Sieve of Eratosthenes(mod)

Jul 29th, 2011
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <math.h>
  5. #include <string.h>
  6. #define EPS 1e-8
  7. #define pi 3.1415926535897932384626433832795028841971693993751
  8. #define N 2147483647
  9.  
  10. int k, ar[20000010];
  11. int ar2[20000010];
  12.  
  13. void SieveOfEratosthenes()
  14. {
  15. int t, i, j, l, n, x;
  16.  
  17. for (i = 1; i <= 20000000; i++) ar[i] = i;
  18.  
  19. for (x = 2; x <= 4473;)
  20. {
  21. for (i = (x * x); i <= 20000000; i = i + x)
  22. {
  23. ar[i] = 0;
  24. }
  25.  
  26. for (i = x + 1; ;i++)
  27. {
  28. if (ar[i] != 0) {x = i; break;}
  29. }
  30. }
  31.  
  32. k = 0;
  33. for (i = 2; i <= 20000000; i++)
  34. {
  35. if (ar[i] != 0) {ar2[k] = ar[i]; k++;}
  36. }
  37. }
  38.  
  39. int main()
  40. {
  41. int i, j, n;
  42. SieveOfEratosthenes();
  43. for (; ;)
  44. {
  45. scanf("%d", &n);
  46. printf("%d\n", ar2[n - 1]);
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement