From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:08:27 +0200 Subject: add: graphs et rushs --- .../tinyprintf/sieve_eratosthenes_advanced/sieve.c | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 rushs/tinyprintf/sieve_eratosthenes_advanced/sieve.c (limited to 'rushs/tinyprintf/sieve_eratosthenes_advanced/sieve.c') diff --git a/rushs/tinyprintf/sieve_eratosthenes_advanced/sieve.c b/rushs/tinyprintf/sieve_eratosthenes_advanced/sieve.c new file mode 100644 index 0000000..7dd4816 --- /dev/null +++ b/rushs/tinyprintf/sieve_eratosthenes_advanced/sieve.c @@ -0,0 +1,39 @@ +#include +#include + +void sieve(int n) +{ + if (n <= 2) + { + return; + } + + // Generate array + int *a = calloc(n, sizeof(int)); + int count = 0; + + // Actual sieve and count + for (int i = 2; i < n; i++) + { + if (a[i] == 0) + { + for (int k = 2 * i; k < n; k += i) + { + a[k] = 1; + } + } + } + + for (int i = 2; i < n; i++) + { + if (a[i] == 0) + { + count++; + } + } + + // Print the count + printf("%d\n", count); + + free(a); +} -- cgit v1.2.3