4 ms·
Very nice! One small note: In an Eratosthenes sieve, you can start crossing out numbers from p^2, since i*p for i<p will have already been crossed out in step i
by esterna 7mo ago
Very nice!
One small note: In an Eratosthenes sieve, you can start crossing out numbers from p^2, since i*p for i<p will have already been crossed out in step i at the latest. You can simply replace
for (size_t i=2; i <= 0xFFFFFFFF / p; i++) {
by
for (size_t i=p; i <= 0xFFFFFFFF / p; i++) {
- adgjlsfhk1 7mo agoand you can get another 2x improvement by incrementing i by 2 for (size_t i=p; i <= 0xFFFFFFFF / p; i+=2) { since every other one will be a multiple of 2