-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheratosthenes.c
More file actions
executable file
·43 lines (24 loc) · 956 Bytes
/
Copy patheratosthenes.c
File metadata and controls
executable file
·43 lines (24 loc) · 956 Bytes
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
41
42
43
// eratostenes.c
// Řešení IJC-DU1, příklad a), 20.3.2024
// Autor: Hugo Bohácsek (xbohach00), FIT
// Přeloženo: gcc (GCC) 13.2.1 20230801
#include "eratosthenes.h"
#include <math.h>
#ifdef USE_INLINE
extern void bitset_free(bitset_t jmeno_pole);
extern bitset_index_t bitset_size(bitset_t jmeno_pole);
extern void bitset_setbit(bitset_t jmeno_pole, bitset_index_t index, int bool_vyraz);
extern int bitset_getbit(bitset_t jmeno_pole, bitset_index_t index);
#endif
void eratosthenes(bitset_t arr){
unsigned int bit;
for (bitset_index_t index = 1; index < sqrt(bitset_size(arr)); index++){
bit = bitset_getbit(arr, index);
bitset_setbit(arr, 0, 1); // hacky fix
if (!bit){
for (bitset_index_t idx = (index * 2) + 2; idx < bitset_size(arr) + 1; idx += index + 1){
bitset_setbit(arr, idx - 1, 1);
}
}
}
}