fork download
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <math.h>
  4.  
  5. int main(void) {
  6. int count;
  7. int i;
  8. int j;
  9. int k;
  10. int c;
  11. int prime;
  12. clock_t start;
  13. clock_t end;
  14. double elapsed;
  15.  
  16. /* input */
  17. scanf("%d", &count);
  18.  
  19. /* measure time */
  20. start = clock();
  21. printf("2\n");
  22. c = 1;
  23. i = 3;
  24. while (c < count) {
  25. /* isPrime */
  26. j = (int)sqrt(i);
  27. k = 3;
  28. prime = 1;
  29. while (k <= j) {
  30. if (i % k == 0) {
  31. prime = 0;
  32. break;
  33. }
  34. k = k + 2;
  35. }
  36.  
  37. /* output */
  38. if (prime) {
  39. c = c + 1;
  40. printf("%d\n", i);
  41. }
  42.  
  43. i = i + 2;
  44. }
  45. end = clock();
  46.  
  47. elapsed = end - start;
  48. printf("elapsed time:%f\n", elapsed);
  49.  
  50. return 0;
  51. }
Success #stdin #stdout 0.01s 1724KB
stdin
10
stdout
2
3
5
7
11
13
17
19
23
29
elapsed time:0.000000