TheAlgorithms-C/project_euler/Problem 07/sol.c
2019-10-01 19:51:55 +05:30

28 lines
555 B
C

#include <stdio.h>
#include <stdlib.h>
int main(void) {
char *sieve;
size_t i;
unsigned count = 0;
size_t n = 1000000;
const unsigned target = 10001;
sieve = calloc(n, sizeof *sieve);
for (i = 2; i < n; i++) {
if (!sieve[i]) {
size_t j;
count++;
if (count == target) {
printf("%lu\n", i);
break;
}
for (j = i * 2; j < n; j += i) {
sieve[j] = 1;
}
}
}
free(sieve);
return 0;
}