Loading topic
% and // operators behave, including the edge cases that cause bugs in prime-relat7 min read%, and that you can read short Python functions with loops and list comprehensions. The previous chapter covered divisibility. Here, "d divides n" means6 min reada divides b when b % a == 0) and how primes and composites are defined. It also assumes you can read short Python functions that use loops and dictionaries. Here we turn those definitions into the most important structural fact abo8 min readn % d == 0 means d divides n, and you are comfortable with introductory Big-O notation. It also uses the definition of a prime from earlier: an integer greater than 1 whose only positive divisors are7 min readd * d > n. This chapter shows why that stopping rule is correct, why it is the right place to stop, and how small implementation choices can quietly break it. It assumes you know the modulo operator, can read Python loops and functions,7 min readn, running it on each candidate repeats a lot of work: the same small divisors get tried over and over. The sieve of Eratosthenes turns the question around. It does not ask "does anything divide this number?" for each num6 min readrange, with the idea that every composite number has a prime factor, and with the square root bound used in trial division. Here we look closely at one8 min readmath.log is the natural logarithm. Earlier chapters showed that primes never run out. This chapter asks how many primes there are below a given number. The answer matte6 min readsieve(n) function from earlier chapters and know why each pass starts at p². It also assumes you know introductory Big-O notation and the prime number theorem's statement that primes near t have density about 1/ln t. The goal is to count the sieve's work exact7 min read//), and bitwise operators (&, |, >>, <<).7 min read