Skip to content

Sieve of Eratosthenes

puzzles

Level 1 of 3

Also called Eratosthenes' sieve and Prime number sieve.

test yourself

Six questions, four to pick from and two for paper.

fresh numbers: the questions a run answers, asked again on new numbers

choose one

question 1

How many crossings does the method make up to 20?

the answer, and why

the answer is B

2 makes 10 - 2 + 1, which is 9, and 3 makes 6 - 3 + 1, which is 4. 5 times 5 is past 20. In all, 13.

if you chose another

  • That is how many numbers are crossed out. 12 and 18 are crossed out twice.
  • That is 2's crossings alone.
  • That is how many primes are left.

question 2

Up to 30, which number is the first to be crossed out a second time?

the answer, and why

the answer is B

2 crossed out 12 as 2 times 6. Then 3 starts at 9, and its next turn crosses out 12 again, as 3 times 4.

if you chose another

  • Only 2 crosses out 6. 3 starts at 9.
  • 3 crosses out 9 first. 2 never does, as 9 is odd.
  • 30 is crossed out a second time later, by 3, after 12, 18 and 24.

question 3

Which number up to 30 is crossed out the most times?

the answer, and why

the answer is D

30 is crossed out by 2, 3 and 5, three times. 5 times 5 is 25, at most 30.

this tests how it works, on the learn page

if you chose another

  • Only twice, by 2 and 3. 5 does not divide it.
  • Only twice, by 2 and 3. 5 does not divide it.
  • 29 is a prime, so it is never crossed out.

question 4

Up to 36, why does 6 cross nothing out?

the answer, and why

the answer is D

6 is 2 times 3, so it was crossed out by 2. Each multiple of 6 is a multiple of 2 too.

this tests where the formula comes from, on the learn page

if you chose another

  • 6 times 6 is 36, which is not past 36, so 6 is still looked at.
  • 6 is 2 times 3, so it is no prime.
  • 12, 18, 24, 30 and 36 are all at most 36.

pen and paper

question 5about 6 minutes

Run the method by hand up to 28.

  1. Which primes cross numbers out, and which numbers does each cross out?
  2. How many crossings are there, and which numbers are crossed out twice?
  3. Which primes are left?
a hint

Each prime starts at itself times itself, and the method stops once that passes 28.

a worked answer

2 crosses out 4, 6, 8 and on to 28, which is 13 numbers. 3 crosses out 9, 12, 15, 18, 21, 24 and 27, which is 7. 4 is crossed out, so it is passed over. 5 crosses out 25 alone. 6 times 6 is 36, past 28, so it stops. That is 21 crossings, and 12, 18 and 24 are crossed out twice. Left are 2, 3, 5, 7, 11, 13, 17, 19 and 23.

this tests how it works, on the learn page

what a full answer includes
  • 2 with 13 numbers, 3 with 7 and 5 with 1, and 4 passed over.
  • 21 crossings, with 12, 18 and 24 twice.
  • The 9 primes from 2 to 23.

question 6about 6 minutes

A friend says the sieve crosses out each number at most once, so it makes fewer than nn crossings.

  1. How many crossings does it make up to 100?
  2. Name a number up to 100 that is crossed out three times.
  3. Where does your friend go wrong?
a hint

Use question 1's line 1, and think about a number with three different prime factors, each with its square at most the number.

a worked answer

Up to 100, 2 makes 49, 3 makes 31, 5 makes 16 and 7 makes 8: 104 crossings, more than 100. 30 is crossed out by 2, 3 and 5. Your friend forgets that a number crossed out before is crossed out again, once by each prime factor whose square is at most the number. So the crossings per number keep growing, to about 2 at a million.

Question 1: how many crossings, CC, does the method make up to nn, for nn of 4 or more?
  1. the move: count each prime's crossings

    the line:
    C=∑p primep×p≤n(⌊np⌋−p+1)C = \sum_{\substack{p \text{ prime} \\ p \times p \le n}} \Bigl(\lfloor \frac{n}{p} \rfloor - p + 1\Bigr)
    primecrosses outascrossings
    24, 6, 8, 10, 12, 14, 162 times 2 to 87
    39, 12, 153 times 3 to 53
    Up to 16. 4 is crossed out, so it crosses nothing out. 12 is crossed out twice.

    why it is allowed: By question 2, the pp not crossed out are the primes: a pp that is no prime is crossed out by its smallest prime factor, which comes first. So only primes cross numbers out, those with pp times pp at most nn. A prime pp crosses out pp times pp, then pp times the next number, p+1p + 1, and on: 2 times 2, then 2 times 3. It stops at pp times ⌊np⌋\lfloor \frac{n}{p} \rfloor, the most that still fits in nn. Counting from pp to ⌊np⌋\lfloor \frac{n}{p} \rfloor, both ends in, is ⌊np⌋−p+1\lfloor \frac{n}{p} \rfloor - p + 1 numbers, as 2 to 8 is 8 - 2 + 1, which is 7. Each counts, crossed out before or not. For 16, 2 makes 7 and 3 makes 5 - 3 + 1, which is 3. In all, 10.

  2. the move: keep only 2's crossings

    the line:
    C≥⌊n2⌋−1C \ge \lfloor \frac{n}{2} \rfloor - 1

    why it is allowed: From 4 up, 2 times 2 is at most nn, so 2's term is there: ⌊n2⌋\lfloor \frac{n}{2} \rfloor, less 2, plus 1. Every other term is at least 1, as pp times pp at most nn puts pp at most ⌊np⌋\lfloor \frac{n}{p} \rfloor, so leaving them out never raises the total. For 16, 10 is at least 7.

  3. the move: drop the rounding

    the line:
    C≥n−12−1C \ge \frac{n - 1}{2} - 1

    why it is allowed: Rounding a half down loses at most a half, so ⌊n2⌋\lfloor \frac{n}{2} \rfloor is at least n−12\frac{n - 1}{2}. For 16, 7 is at least 6.5.

  4. the move: one fraction

    the line:
    C≥n−32C \ge \frac{n - 3}{2}

    why it is allowed: 1 is 2 halves, and n−1n - 1 less 2 is n−3n - 3. For 16, 6.5.

  5. the move: read the bound

    the line:
    C∈Ω(n)C \in \Omega(n)

    why it is allowed: By line 4. From 6 up, n−3n - 3 is at least half of nn, so CC is at least a quarter of nn, the fixed multiple. Ω(n)\Omega(n) means at least a fixed multiple of nn, above 0, from some nn on.

  6. the move: drop the rounding

    the line:
    C≤∑p primep×p≤n(np−p+1)C \le \sum_{\substack{p \text{ prime} \\ p \times p \le n}} \Bigl(\frac{n}{p} - p + 1\Bigr)

    why it is allowed: Rounding down makes no bigger, so ⌊np⌋\lfloor \frac{n}{p} \rfloor is at most np\frac{n}{p}. For 16, 2's term stays 7, and 3's becomes 3.33.

  7. the move: drop what is below 0

    the line:
    C≤∑p primep×p≤nnpC \le \sum_{\substack{p \text{ prime} \\ p \times p \le n}} \frac{n}{p}

    why it is allowed: −p+1- p + 1 is below 0, as pp is at least 2. For 16, 7 becomes 8, and 3.33 becomes 5.33.

  8. the move: every number, not only primes

    the line:
    C≤∑k=2⌊n⌋nkC \le \sum_{k=2}^{\lfloor \sqrt{n} \rfloor} \frac{n}{k}

    why it is allowed: p×p≤np \times p \le n puts pp at most n\sqrt{n}, so at most ⌊n⌋\lfloor \sqrt{n} \rfloor. Add a term for every whole number kk from 2 to there, prime or not: more terms, each above 0. For 16, the root is 4, and 4 adds 16 over 4, so 13.33 becomes 17.33.

  9. the move: name the harmonic sum

    the line:
    C≤n(H(⌊n⌋)−1)C \le n \bigl(H(\lfloor \sqrt{n} \rfloor) - 1\bigr)
    where does this come from?
    question 4 of the page expected costHow does 1+12+13+⋯+1n1 + \frac{1}{2} + \frac{1}{3} + \dots + \frac{1}{n} grow?
    1. the move: name the sum

      the line:
      H=∑k=1n1kH = \sum_{k=1}^{n} \frac{1}{k}

      why it is allowed: Let HH be the harmonic sum to 1 over nn, for nn from 2.

    2. the move: group in blocks

      the line:
      blocks, each starting at1 over a power of 2\begin{gathered} \text{blocks, each starting at} \\ \text{1 over a power of 2} \end{gathered}
      blocktermsadds to01≤ 112≤ 124≤ 135≤ 1
      The sum to 1 over 12, about 3.10, each term a column 1 over k tall. Behind each place of a block stands its first term, dashed, so 4 dashed columns of 1 over 4 make 1. The last block is cut short.

      why it is allowed: Number blocks by jj from 0. Block jj starts at 1 over 2 to the power jj: 1, 1 over 2, 1 over 4, 1 over 8. It stops just before the next start, so it has 2 to the power jj terms: 1 over 4 to 1 over 7 are 4. The last block may be cut short at 1 over nn.

    3. the move: each block at most 1

      the line:
      H≤the number of blocksH \le \text{the number of blocks}

      why it is allowed: Each term of block jj is at most its first, 1 over 2 to the power jj, as a bigger number underneath makes a smaller fraction. So its 2 to the power jj terms, or fewer, add to at most 1. HH is at most 1 per block: 4 for 12.

    4. the move: count the blocks

      the line:
      H≤⌊log⁡2 n⌋+1H \le \lfloor \log_2\, n \rfloor + 1
      where does this come from?
      question 2 of the page halving and logarithmsHalve nn, rounding down each time. How many halvings reach 1?
      1. the move: name the log rounded down

        the line:
        K=⌊log⁡2 n⌋K = \lfloor \log_2\, n \rfloor
        numberlog× 2+ 14283164113.46352.322211100
        Rounding down, 11 halves to 5, 2 and 1. In blue, each log rounded down: 3, 2, 1, 0, one less at each halving.

        why it is allowed: Here nn is the number halved, from 2 up; for 11, KK is 3.

      2. the move: rounding down never adds

        the line:
        ⌊log⁡2 n⌋≤log⁡2 n\lfloor \log_2\, n \rfloor \le \log_2\, n

        why it is allowed: For 11, 3 is at most 3.46.

      3. the move: rounding down takes off less than 1

        the line:
         log⁡2 n<⌊log⁡2 n⌋+1\begin{gathered} \,\log_2\, n \\ < \lfloor \log_2\, n \rfloor + 1 \end{gathered}

        why it is allowed: For 11, 4 is above 3.46.

      4. the move: raise 2 to each side of line 2

        the line:
        2⌊log⁡2 n⌋≤2log⁡2 n2^{\lfloor \log_2\, n \rfloor} \le 2^{\log_2\, n}

        why it is allowed: 2 raised to a bigger power gives a bigger number. For 11, 8 is at most about 11.

      5. the move: 2 to the log of n is n

        the line:
        2⌊log⁡2 n⌋≤n2^{\lfloor \log_2\, n \rfloor} \le n

        why it is allowed: By what a log is. For 11, 8 is at most 11.

      6. the move: raise 2 to each side of line 3

        the line:
        2log⁡2 n<2⌊log⁡2 n⌋+12^{\log_2\, n} < 2^{\lfloor \log_2\, n \rfloor + 1}

        why it is allowed: As in line 4. For 11, about 11 is below 16.

      7. the move: 2 to the log of n is n

        the line:
        n<2⌊log⁡2 n⌋+1n < 2^{\lfloor \log_2\, n \rfloor + 1}

        why it is allowed: As in line 5. For 11, 11 is below 16.

      8. the move: halve both sides of line 5

        the line:
        2⌊log⁡2 n⌋/2≤n/22^{\lfloor \log_2\, n \rfloor} / 2 \le n / 2

        why it is allowed: For 11, 4 is at most 5.5, which is not whole.

      9. the move: write the half as a power

        the line:
        2⌊log⁡2 n⌋−1≤n/22^{\lfloor \log_2\, n \rfloor - 1} \le n / 2

        why it is allowed: Half a power of 2 has one 2 fewer. Half of 8 is 4.

      10. the move: round the half down

        the line:
        2⌊log⁡2 n⌋−1≤⌊n/2⌋2^{\lfloor \log_2\, n \rfloor - 1} \le \lfloor n / 2 \rfloor

        why it is allowed: ⌊n/2⌋\lfloor n / 2 \rfloor is the half rounded down, 5 for 11. A whole number at most 5.5 is at most 5. The left side, 4 for 11, is whole, as KK is at least 1 for nn from 2 up.

      11. the move: halve both sides of line 7

        the line:
        n/2<2⌊log⁡2 n⌋+1/2n / 2 < 2^{\lfloor \log_2\, n \rfloor + 1} / 2

        why it is allowed: For 11, 5.5 is below 8.

      12. the move: write the half as a power

        the line:
        n/2<2⌊log⁡2 n⌋n / 2 < 2^{\lfloor \log_2\, n \rfloor}

        why it is allowed: As in line 9. Half of 16 is 8.

      13. the move: round the half down

        the line:
        ⌊n/2⌋<2⌊log⁡2 n⌋\lfloor n / 2 \rfloor < 2^{\lfloor \log_2\, n \rfloor}

        why it is allowed: Rounding down never adds. For 11, 5 is below 8.

      14. the move: take the log of line 10

        the line:
         log⁡2 2⌊log⁡2 n⌋−1≤log⁡2 ⌊n/2⌋\begin{gathered} \,\log_2\, 2^{\lfloor \log_2\, n \rfloor - 1} \\ \le \log_2\, \lfloor n / 2 \rfloor \end{gathered}

        why it is allowed: A bigger number has a bigger log. For 11, the log of 4 is at most the log of 5.

      15. the move: the log of a power of 2 is the power

        the line:
        ⌊log⁡2 n⌋−1≤log⁡2 ⌊n/2⌋\begin{gathered} \lfloor \log_2\, n \rfloor - 1 \\ \le \log_2\, \lfloor n / 2 \rfloor \end{gathered}

        why it is allowed: For 11, the log of 4 is 2, at most about 2.32.

      16. the move: take the log of line 13

        the line:
         log⁡2 ⌊n/2⌋<log⁡2 2⌊log⁡2 n⌋\begin{gathered} \,\log_2\, \lfloor n / 2 \rfloor \\ < \log_2\, 2^{\lfloor \log_2\, n \rfloor} \end{gathered}

        why it is allowed: As in line 14. For 11, the log of 5 is below the log of 8.

      17. the move: the log of a power of 2 is the power

        the line:
         log⁡2 ⌊n/2⌋<⌊log⁡2 n⌋\begin{gathered} \,\log_2\, \lfloor n / 2 \rfloor \\ < \lfloor \log_2\, n \rfloor \end{gathered}

        why it is allowed: For 11, about 2.32 is below 3.

      18. the move: round the log down

        the line:
        ⌊log⁡2 ⌊n/2⌋⌋=⌊log⁡2 n⌋−1\begin{gathered} \lfloor \log_2\, \lfloor n / 2 \rfloor \rfloor \\ = \lfloor \log_2\, n \rfloor - 1 \end{gathered}
        the numberat leastbelowits log rounded down
        118163
        5482
        2241
        1120
        Each halving takes 1 off the log rounded down.

        why it is allowed: By lines 15 and 17, the log of the half is at least one less than KK and below KK, so it rounds down to one less. For 11, about 2.32 rounds down to 2.

      19. the move: use line 18 again and again

        the line:
        after K halvings,rounding down,the log roundeddown is 0\begin{gathered} \text{after } K \text{ halvings,} \\ \text{rounding down,} \\ \text{the log rounded} \\ \text{down is 0} \end{gathered}

        why it is allowed: While the log rounded down is 1 or more, the number is at least 2 to the power 1, which is 2. So line 18 takes 1 off each halving, down to 0 after KK. For 11, 3, 2, 1, 0.

      20. the move: a log rounded down to 0 belongs to 1

        the line:
        K halvings,rounding down,bring n to 1\begin{gathered} K \text{ halvings,} \\ \text{rounding down,} \\ \text{bring } n \text{ to 1} \end{gathered}

        why it is allowed: Such a log is at least 0 and below 1, so its number is at least 1 and below 2. It is 1.

      the whole page: halving and logarithms

      why it is allowed: ⌊log⁡2 n⌋\lfloor \log_2\, n \rfloor is read the log of nn rounded down. By lines 5 and 7 of the page halving and logarithms, 2 to that power is at most nn, and the next power of 2 is above nn. So ⌊log⁡2 n⌋+1\lfloor \log_2\, n \rfloor + 1 blocks start at 1 over 2 to the powers 0 to ⌊log⁡2 n⌋\lfloor \log_2\, n \rfloor. For 12, 3.58 rounds down to 3: the 4 blocks of line 2.

    5. the move: drop the rounding

      the line:
      H≤log⁡2 n+1H \le \log_2\, n + 1

      why it is allowed: Rounding down never adds, so putting log⁡2 n\log_2\, n for ⌊log⁡2 n⌋\lfloor \log_2\, n \rfloor can never lower the right side. For 12, 4 becomes about 4.58.

    6. the move: a fact about n

      the line:
      1≤log⁡2 n1 \le \log_2\, n

      why it is allowed: nn is at least 2, the log of 2 is 1, and a bigger number has a bigger log.

    7. the move: put the log in place of the 1

      the line:
      H≤log⁡2 n+log⁡2 nH \le \log_2\, n + \log_2\, n

      why it is allowed: By line 6 this makes the right side of line 5 no smaller. For 12, 4.58 becomes about 7.17.

    8. the move: add the logs

      the line:
      H≤2 log⁡2 nH \le 2 \,\log_2\, n

      why it is allowed: Two lots of log⁡2 n\log_2\, n.

    9. the move: a ceiling

      the line:
      H∈O(log⁡2 n)H \in O(\log_2\, n)

      why it is allowed: By line 8, HH is at most 2 times log⁡2 n\log_2\, n for every nn from 2. H∈O(log⁡2 n)H \in O(\log_2\, n), read HH is in big O of log⁡2 n\log_2\, n, says a fixed multiple of log⁡2 n\log_2\, n is a ceiling of HH: here 2.

    10. the move: blocks after the first term

      the line:
      after the first term,blocks, each ending at1 over a power of 2\begin{gathered} \text{after the first term,} \\ \text{blocks, each ending at} \\ \text{1 over a power of 2} \end{gathered}
      blocktermsadds tofirst11≥ ½22≥ ½34≥ ½left over
      The sum to 1 over 12. Inside each term of a block stands its last term, dashed, so 2 dashed columns of 1 over 4 make one half. 1 over 9 to 1 over 12 are left over.

      why it is allowed: For a floor, group the terms after the first in blocks ending at 1 over 2, 1 over 4, 1 over 8 and on. Each term is then at least its block's last. Whole blocks end at 1 over the powers of 2 from 2 to nn.

    11. the move: drop the leftovers

      the line:
      H is at least 1 plusthe whole blocksadded up\begin{gathered} H \text{ is at least 1 plus} \\ \text{the whole blocks} \\ \text{added up} \end{gathered}

      why it is allowed: Leftover terms are above zero, so leaving them out makes the total no bigger.

    12. the move: whole blocks at least one half

      the line:
      H≥1+12×the numberof whole blocks\begin{gathered} H \ge 1 + \frac{1}{2} \times \text{the number} \\ \text{of whole blocks} \end{gathered}

      why it is allowed: Number the whole blocks by ii from 1. Block ii runs from just after 1 over half of 2 to the power ii to 1 over 2 to the power ii. That is half that many terms, each at least its last, so at least one half. For 12, 1 over 3 + 1 over 4 is at least 2 times 1 over 4. With line 11, HH is at least 1 plus one half per whole block: 2.5.

    13. the move: count the whole blocks

      the line:
      H≥1+⌊log⁡2 n⌋2H \ge 1 + \frac{\lfloor \log_2\, n \rfloor}{2}
      where does this come from?
      question 2 of the page halving and logarithmsHalve nn, rounding down each time. How many halvings reach 1?
      1. the move: name the log rounded down

        the line:
        K=⌊log⁡2 n⌋K = \lfloor \log_2\, n \rfloor
        numberlog× 2+ 14283164113.46352.322211100
        Rounding down, 11 halves to 5, 2 and 1. In blue, each log rounded down: 3, 2, 1, 0, one less at each halving.

        why it is allowed: Here nn is the number halved, from 2 up; for 11, KK is 3.

      2. the move: rounding down never adds

        the line:
        ⌊log⁡2 n⌋≤log⁡2 n\lfloor \log_2\, n \rfloor \le \log_2\, n

        why it is allowed: For 11, 3 is at most 3.46.

      3. the move: rounding down takes off less than 1

        the line:
         log⁡2 n<⌊log⁡2 n⌋+1\begin{gathered} \,\log_2\, n \\ < \lfloor \log_2\, n \rfloor + 1 \end{gathered}

        why it is allowed: For 11, 4 is above 3.46.

      4. the move: raise 2 to each side of line 2

        the line:
        2⌊log⁡2 n⌋≤2log⁡2 n2^{\lfloor \log_2\, n \rfloor} \le 2^{\log_2\, n}

        why it is allowed: 2 raised to a bigger power gives a bigger number. For 11, 8 is at most about 11.

      5. the move: 2 to the log of n is n

        the line:
        2⌊log⁡2 n⌋≤n2^{\lfloor \log_2\, n \rfloor} \le n

        why it is allowed: By what a log is. For 11, 8 is at most 11.

      6. the move: raise 2 to each side of line 3

        the line:
        2log⁡2 n<2⌊log⁡2 n⌋+12^{\log_2\, n} < 2^{\lfloor \log_2\, n \rfloor + 1}

        why it is allowed: As in line 4. For 11, about 11 is below 16.

      7. the move: 2 to the log of n is n

        the line:
        n<2⌊log⁡2 n⌋+1n < 2^{\lfloor \log_2\, n \rfloor + 1}

        why it is allowed: As in line 5. For 11, 11 is below 16.

      8. the move: halve both sides of line 5

        the line:
        2⌊log⁡2 n⌋/2≤n/22^{\lfloor \log_2\, n \rfloor} / 2 \le n / 2

        why it is allowed: For 11, 4 is at most 5.5, which is not whole.

      9. the move: write the half as a power

        the line:
        2⌊log⁡2 n⌋−1≤n/22^{\lfloor \log_2\, n \rfloor - 1} \le n / 2

        why it is allowed: Half a power of 2 has one 2 fewer. Half of 8 is 4.

      10. the move: round the half down

        the line:
        2⌊log⁡2 n⌋−1≤⌊n/2⌋2^{\lfloor \log_2\, n \rfloor - 1} \le \lfloor n / 2 \rfloor

        why it is allowed: ⌊n/2⌋\lfloor n / 2 \rfloor is the half rounded down, 5 for 11. A whole number at most 5.5 is at most 5. The left side, 4 for 11, is whole, as KK is at least 1 for nn from 2 up.

      11. the move: halve both sides of line 7

        the line:
        n/2<2⌊log⁡2 n⌋+1/2n / 2 < 2^{\lfloor \log_2\, n \rfloor + 1} / 2

        why it is allowed: For 11, 5.5 is below 8.

      12. the move: write the half as a power

        the line:
        n/2<2⌊log⁡2 n⌋n / 2 < 2^{\lfloor \log_2\, n \rfloor}

        why it is allowed: As in line 9. Half of 16 is 8.

      13. the move: round the half down

        the line:
        ⌊n/2⌋<2⌊log⁡2 n⌋\lfloor n / 2 \rfloor < 2^{\lfloor \log_2\, n \rfloor}

        why it is allowed: Rounding down never adds. For 11, 5 is below 8.

      14. the move: take the log of line 10

        the line:
         log⁡2 2⌊log⁡2 n⌋−1≤log⁡2 ⌊n/2⌋\begin{gathered} \,\log_2\, 2^{\lfloor \log_2\, n \rfloor - 1} \\ \le \log_2\, \lfloor n / 2 \rfloor \end{gathered}

        why it is allowed: A bigger number has a bigger log. For 11, the log of 4 is at most the log of 5.

      15. the move: the log of a power of 2 is the power

        the line:
        ⌊log⁡2 n⌋−1≤log⁡2 ⌊n/2⌋\begin{gathered} \lfloor \log_2\, n \rfloor - 1 \\ \le \log_2\, \lfloor n / 2 \rfloor \end{gathered}

        why it is allowed: For 11, the log of 4 is 2, at most about 2.32.

      16. the move: take the log of line 13

        the line:
         log⁡2 ⌊n/2⌋<log⁡2 2⌊log⁡2 n⌋\begin{gathered} \,\log_2\, \lfloor n / 2 \rfloor \\ < \log_2\, 2^{\lfloor \log_2\, n \rfloor} \end{gathered}

        why it is allowed: As in line 14. For 11, the log of 5 is below the log of 8.

      17. the move: the log of a power of 2 is the power

        the line:
         log⁡2 ⌊n/2⌋<⌊log⁡2 n⌋\begin{gathered} \,\log_2\, \lfloor n / 2 \rfloor \\ < \lfloor \log_2\, n \rfloor \end{gathered}

        why it is allowed: For 11, about 2.32 is below 3.

      18. the move: round the log down

        the line:
        ⌊log⁡2 ⌊n/2⌋⌋=⌊log⁡2 n⌋−1\begin{gathered} \lfloor \log_2\, \lfloor n / 2 \rfloor \rfloor \\ = \lfloor \log_2\, n \rfloor - 1 \end{gathered}
        the numberat leastbelowits log rounded down
        118163
        5482
        2241
        1120
        Each halving takes 1 off the log rounded down.

        why it is allowed: By lines 15 and 17, the log of the half is at least one less than KK and below KK, so it rounds down to one less. For 11, about 2.32 rounds down to 2.

      19. the move: use line 18 again and again

        the line:
        after K halvings,rounding down,the log roundeddown is 0\begin{gathered} \text{after } K \text{ halvings,} \\ \text{rounding down,} \\ \text{the log rounded} \\ \text{down is 0} \end{gathered}

        why it is allowed: While the log rounded down is 1 or more, the number is at least 2 to the power 1, which is 2. So line 18 takes 1 off each halving, down to 0 after KK. For 11, 3, 2, 1, 0.

      20. the move: a log rounded down to 0 belongs to 1

        the line:
        K halvings,rounding down,bring n to 1\begin{gathered} K \text{ halvings,} \\ \text{rounding down,} \\ \text{bring } n \text{ to 1} \end{gathered}

        why it is allowed: Such a log is at least 0 and below 1, so its number is at least 1 and below 2. It is 1.

      the whole page: halving and logarithms

      why it is allowed: As in line 4, whole blocks end at 1 over 2 to the powers 1 to ⌊log⁡2 n⌋\lfloor \log_2\, n \rfloor, that many blocks. For 12, 3.

    14. the move: rounding takes off less than 1

      the line:
      H≥1+log⁡2 n−12H \ge 1 + \frac{\log_2\, n - 1}{2}

      why it is allowed: Rounding down takes off less than 1, so putting log⁡2 n\log_2\, n less 1 for ⌊log⁡2 n⌋\lfloor \log_2\, n \rfloor can only lower the right side. For 12, 2.5 becomes about 2.29.

    15. the move: halve each part

      the line:
      H≥1+log⁡2 n2−12H \ge 1 + \frac{\log_2\, n}{2} - \frac{1}{2}

      why it is allowed: Half of (log⁡2 n\log_2\, n less 1) is half of log⁡2 n\log_2\, n, less one half.

    16. the move: change the order

      the line:
      H≥1−12+log⁡2 n2H \ge 1 - \frac{1}{2} + \frac{\log_2\, n}{2}

      why it is allowed: Adding and taking away go in any order.

    17. the move: 1 less one half

      the line:
      H≥12+log⁡2 n2H \ge \frac{1}{2} + \frac{\log_2\, n}{2}

      why it is allowed: 1 less one half is one half.

    18. the move: drop the one half

      the line:
      H≥log⁡2 n2H \ge \frac{\log_2\, n}{2}

      why it is allowed: Taking away one half makes the right side smaller. For 12, about 1.79.

    19. the move: a floor

      the line:
      H∈Ω(log⁡2 n)H \in \Omega(\log_2\, n)
      the sumterms024681005101520the sumterms024681005101520
      • the ceiling, 2 log⁡2 n2 \,\log_2\, n
      • the harmonic sum
      • the floor, log⁡2 n2\frac{\log_2\, n}{2}
      From 2 terms on, the harmonic sum lies between its ceiling and floor. At 16: 8, about 3.38, and 2.

      why it is allowed: By line 18, HH is at least one half times log⁡2 n\log_2\, n for every nn from 2. H∈Ω(log⁡2 n)H \in \Omega(\log_2\, n), read HH is in big omega of log⁡2 n\log_2\, n, says a fixed multiple of log⁡2 n\log_2\, n, above zero, is a floor of HH.

    20. the move: ceiling and floor together

      the line:
      H∈Θ(log⁡2 n)H \in \Theta(\log_2\, n)

      why it is allowed: H∈Θ(log⁡2 n)H \in \Theta(\log_2\, n), read HH is in big theta of log⁡2 n\log_2\, n, says both: by lines 9 and 19, for every nn from 2, HH lies between one half and 2 times log⁡2 n\log_2\, n. It grows like log⁡2 n\log_2\, n.

    the whole page: expected cost

    why it is allowed: Take nn out of each term, leaving nn times (1 over 2, plus 1 over 3, and on). That is HH without its first 1. For 16, 16 over 2, plus 16 over 3, plus 16 over 4, is 16 times (H(4)H(4) less 1), about 17.33. The fold shows how HH grows.

  10. the move: how big the harmonic sum gets

    the line:
    H(⌊n⌋)≤log⁡2 ⌊n⌋+1H(\lfloor \sqrt{n} \rfloor) \le \log_2\, \lfloor \sqrt{n} \rfloor + 1

    why it is allowed: The fold at line 9 shows this in its line 5, with ⌊n⌋\lfloor \sqrt{n} \rfloor in place of its nn. From 4 up, that is at least 2, as the fold needs. For 16, H(4)H(4) is about 2.08, at most 3.

  11. the move: put it in

    the line:
    C≤n log⁡2 ⌊n⌋C \le n \,\log_2\, \lfloor \sqrt{n} \rfloor

    why it is allowed: Put line 10 into line 9. Its + 1 and - 1 cancel. For 16, 16 times 2, which is 32.

  12. the move: drop the rounding

    the line:
    C≤n log⁡2 nC \le n \,\log_2\, \sqrt{n}

    why it is allowed: ⌊n⌋\lfloor \sqrt{n} \rfloor is at most n\sqrt{n}, and a bigger number has a bigger log.

  13. the move: half the log

    the line:
    C≤n2 log⁡2 nC \le \frac{n}{2} \,\log_2\, n
    102104106108101102103104105106107101102103104105106107108109101102103104105106107
    • the floor, ⌊n2⌋−1\lfloor \frac{n}{2} \rfloor - 1
    • the crossings, CC
    • the ceiling, n2 log⁡2 n\frac{n}{2} \,\log_2\, n
    The floor, the crossings and the ceiling on a log-log plot, each mark ten times the one before, as in section 2. The crossings lie between them, about 2 times the floor at 100 and 4 times at a million.

    why it is allowed: For 16, its root is 4, which is 2 to the power 2, and 16 is 2 to the power 4: half of 4 is 2. In general, 2 to the power of half of log⁡2 n\log_2\, n, times itself, is 2 to the power log⁡2 n\log_2\, n, which is nn. So it is n\sqrt{n}, and log⁡2 n\log_2\, \sqrt{n} is half of log⁡2 n\log_2\, n. For 16, 8 times 4, which is 32.

  14. the move: read the bound

    the line:
    C∈O(n log⁡2 n)C \in O(n \,\log_2\, n)

    why it is allowed: By line 13, with the fixed multiple a half. Lines 5 and 14 grow differently, as nn and n log⁡2 nn \,\log_2\, n, so they make no Θ\Theta. The tight growth needs Mertens's 1874 sum over the primes, not worked out here. At a million, the floor gives 499,999, the count is 2,122,048 and the ceiling 9,965,784, so the count is about 4 times the floor and a fifth of the ceiling.

try it with a small nn: at n=16n = 16, line 1 gives C=10C = 10, which you can work out by hand

this tests where the formula comes from, on the learn page

what a full answer includes
  • 104 crossings.
  • A number such as 30, 60 or 90.
  • A number crossed out before is crossed out again.