Confusion with C version of sieve problem

Can someone explain why this array has six elements, but the expected count is 4 ?

I spot checked the sieve tests for the different languages and they
don’t have that.

The header shows,

/// Calculate at most `max_primes` prime numbers in the interval [2,limit]
/// using the Sieve of Eratosthenes and store the prime numbers in `primes`
/// in increasing order.
/// The function returns the number of calculated primes.
uint32_t sieve(uint32_t limit, uint32_t *primes, size_t max_primes);

The function is supposed to compute 4 primes within the limit of 13. I’m not sure why the array is populated until 13 but I believe the test ignores everything after the first four elements.

Thanks, I got my tests to pass, by just ignoring the length of the array.
And I assume it doesn’t get used, because mine doesn’t match the test
code.

I still think it might be wrong, but i’m speedrunning the C track and already spent too long on sieve. :) thanks

That’s what the code review button is there for ;)

1 Like