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