-
Notifications
You must be signed in to change notification settings - Fork 0
/
primes.c
40 lines (31 loc) · 926 Bytes
/
primes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// primes.c
// Řešení IJC-DU1, příklad a), 20.3.2022
// Autor: Ondřej Zobal, FIT
// Přeloženo: gcc 11.2
#include <stdio.h>
#include <time.h>
#include "eratosthenes.h"
#define LIMIT 300000001
#define PRINT_LIMIT 10
void print_last_primes(bitset_t pole, int print_limit) {
bitset_index_t last_numbers[print_limit];
// Printing last primes.
bitset_index_t j = 0;
for (bitset_index_t i = bitset_size(pole)-1; i > 0 && j < PRINT_LIMIT; i--) {
if (!bitset_getbit(pole, i)) {
last_numbers[j++] = i+1;
}
}
for (int i = print_limit-1; i >= 0; i--) {
printf("%ld\n", last_numbers[i]);
}
}
int main() {
clock_t start = clock();
bitset_alloc(numbers, LIMIT);
Eratosthenes(numbers);
print_last_primes(numbers, PRINT_LIMIT);
bitset_free(numbers);
fprintf(stderr, "Time=%.3g\n", (double)(clock()-start)/CLOCKS_PER_SEC);
return 0;
}