Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 35s1 days 16 hours 1 minutes 35 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 35s1 days 16 hours 1 minutes 35 seconds.

Sign in to watch this lesson
Algorithms - Bits and Number Theory · 4:50
Instead of testing each number for divisors, let every prime cross out its own multiples. On the 1..16 grid we see the wasted double marks, then start each prime at its square and stop at the square root of n, which brings the work down to about n log log n. Measured on this Mac at n = 10^8, the segmented sieve that works one L1-sized block at a time runs more than five times faster than the plain byte array, and the same block idea finds the primes in a window far from zero.