-
Notifications
You must be signed in to change notification settings - Fork 0
/
eratosthenes.c
31 lines (26 loc) · 938 Bytes
/
eratosthenes.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
// eratosthenes.c
// Řešení IJC-DU1, příklad a), 20.3.2022
// Autor: Ondřej Zobal, FIT
// Přeloženo: gcc 11.2
#include <math.h>
#include "eratosthenes.h"
// FIXME čtyřicet dvojka nějakým způsobem odjevábá sedimčku.
// TODO předělej to na inliny a vydebuguj to reee
#ifdef USE_INLINE
extern void bitset_free(bitset_t name);
extern bitset_index_t bitset_size(bitset_t array);
extern void bitset_setbit(bitset_t array, bitset_index_t index, int expression);
extern int bitset_getbit(bitset_t array, bitset_index_t index);
#endif
void Eratosthenes(bitset_t pole) {
// Calculating primes.
for (bitset_index_t i = 1; i < sqrt(bitset_size(pole)); i++) {
unsigned int bit = bitset_getbit(pole, i);
bitset_setbit(pole, 0, 1);
if(!bit) {
for (bitset_index_t j = i+i+2; j < bitset_size(pole)+1; j+=i+1) {
bitset_setbit(pole, j-1, 1);
}
}
}
}