~cpp #include <stdio.h> #include <time.h> #define MAX_PRIME 50000 int main(void) { int i, j, flag, arr_p, tmp, count = 0; int arr[10000] = {2, }; time_t start, end; start = clock(); arr_p = 1; for (i = 3; i < MAX_PRIME; i += 2) { for (j = 0, flag = 1, tmp = i >> 1; tmp >= arr[j]; j++) { if (i % arr[j] == 0) { flag = 0; break; } } if (flag) { arr[arr_p] = i; arr_p++; } } i = 0; end = clock(); while (arr[i] != 0) { printf("%d ", arr[i++]); count++; } printf("\n%f\n", (double)(end - start) / CLK_TCK); printf("#%d prime numbers.\n", count); return 0; }