Mathematics Book 1 Exercises: Arithmetic and NumbersMaths Book 1 · Exercises
0 / 0

Workbench / Mathematics Book 1 Exercises: Arithmetic and Numbers

B1·05

Factors, Multiples and Primes

Exercises for chapter 5: divisibility tests proved, remainders that add and multiply, the sieve, Euclid's primes and his algorithm, counting factors from a factorisation (checked by brute force), Euclid's numbers that aren't prime, check digits measured against typing errors, recurring events that coincide or never can, and senior exercises on hash table sizes, cryptography and scheduled jobs.

20 topics · ~6 min read
Updated Suggest a correction

Start here: how these exercises work

Write your answer in the box first; hints open one at a time as you write, and the solution a couple of minutes after the last hint. Theory is in your own words, practice and programs come with real output (Python 3.13), cumulative projects use chapters 1 to 5 together, what the chapter leaves out explains what it skips, and senior exercises put the ideas into designs and reviews.

Theory

T1. Why the test for 4 looks at two digits

Explain why divisibility by 4 depends only on the last two digits, but divisibility by 3 depends on every digit. Then find the test for 8, and explain why there's no last-digits test for 3.

T2. Remainders on a clock

It's 9 o'clock. What time will it be in 100 hours? In 1,000 hours? Explain using remainders, and then say what day of the week it will be 1,000 days after a Friday.

T3. Why 1 isn't prime, in your own words

Someone says "1 is only divisible by 1 and itself, so it's prime". Give two reasons, one from the definition and one from what primes are for, why mathematicians don't count it.

T4. Euclid's proof, carefully

Write Euclid's proof that there are infinitely many primes in your own words. Then explain exactly what is wrong with the common version "multiply all the primes and add 1, and you get a new prime".

T5. Euclid's algorithm, explained

Explain why gcd(a,b) =gcd(b,amodb), using the divisibility facts from the chapter. Then explain why the algorithm must stop.

T6. Combining divisibility tests

Explain why a number divisible by 3 and by 4 must be divisible by 12, while a number divisible by 4 and by 6 need not be divisible by 24. State the general rule.

Practice and programs

P1. By hand

(a) Which of 2, 3, 4, 5, 6, 8, 9, 11 divide 123,321? (b) Factorise 2,310 and 2,431. (c) Find gcd and lcm of 2,310 and 2,431 by factorising, then by Euclid's algorithm. (d) How many factors does 2,310 have? (e) List the primes between 150 and 200.

P2. Counting factors, two ways

Write a function that counts a number's factors from its prime factorisation (multiply the exponents plus one) and check it against counting by trial for every number up to 10,000. Which number up to 10,000 has the most factors? How many numbers up to 10,000 have an odd number of factors, and why?

P3. Euclid's numbers

Compute N =p1×⋯×pk+1 for the first 1 to 9 primes and find each one's smallest prime factor. Which are prime? Does any counter-example hurt Euclid's proof?

P4. Check digits against typing errors

Payment card numbers end in a Luhn check digit; a naive scheme just makes the digits add up to a multiple of 10. Simulate 50,000 sixteen-digit numbers under each scheme, introduce one wrong digit or one swap of neighbours, and measure how often each scheme catches the error. Then find a swap Luhn can't see.

Cumulative projects (chapters so far: 01–05)

C1. Ledger IDs that catch every typo

Give each ledger entry from the capstone an 8-digit ID with an ISBN-10-style check character: weight the digits 2, 3, 4, … from the right, and choose the check value that makes the weighted sum a multiple of 11 (writing 10 as X). Keep the ID as text (chapter 1), fixed-width with leading zeros (chapter 2). Measure how many single wrong digits and swapped neighbours it catches over 100,000 IDs, and explain why it does better than Luhn.

C2. When do recurring events coincide?

The bins go out every 4 days and the plants are watered every 6. Find when they next coincide if both happen today; then if the bins start on day 1 and watering on day 2; then on days 1 and 3. Then try every 4 days from day 1 and every 7 days from day 3. Explain which cases can never coincide, without searching.

What the chapter leaves out

Bézout's identity and the extended algorithm

Running Euclid's algorithm backwards writes the gcd as a combination of the two numbers: for 1071 and 462, 21 =1071×(−3)+462×7 (check: −3213+3234=21). In general gcd(a,b)=ax+by for some whole numbers x,y (Bézout's identity), and the extended Euclidean algorithm finds them. It's how you solve "7x≡1(mod40)" (x=23, since 7×23 =161 =4×40+1), which is exactly the step that makes an RSA private key.

The Chinese remainder theorem

If m and n are coprime, then for any remainders r and s there's exactly one number between 0 and mn−1 that leaves r on division by m and s on division by n. Cumulative project C2 found such numbers by search; the theorem says they always exist when the moduli are coprime, and the extended algorithm computes them directly. It appears in a Chinese text of the third to fifth century CE (the Sunzi Suanjing), and it's used in calendars, in fast arithmetic on huge numbers (compute modulo several primes, combine at the end) and in RSA implementations.

Fermat's little theorem and fast primality tests

For a prime p and any a not divisible by p, ap−1≡1(modp) (Fermat, 1640). Turned around, if an−1≢1(modn), then n is certainly not prime, a test that needs no factoring and runs fast even for numbers with hundreds of digits (computing an−1modn by repeated squaring). The Miller–Rabin test sharpens it so that each random a catches a composite with probability at least ¾; a few dozen rounds make an error astronomically unlikely. That's why generating large primes for keys is easy while factoring their product is hard.

Primes in the wild

The largest primes known are almost all Mersenne primes, 2p−1, because there's a fast special test for them; volunteers in the GIMPS project find new ones, which have tens of millions of digits. Primes also matter in engineering in humbler ways: hash table sizes, the periods of pseudo-random generators, gear tooth counts and cicada life cycles (13 and 17 years, a famous but debated example of prime periods reducing overlaps).

Senior exercises

S1. Why some hash tables use prime sizes

A hash table puts a key in bucket key % size. Your keys are all multiples of 4 (memory addresses, or sizes). Compare 16 buckets with 17, measure, and explain. Then explain why many modern hash tables use powers of two anyway.

S2. What RSA asks of factoring

Explain to a product manager, without formulas, why an RSA key's security depends on factoring being hard, and why a 2048-bit key is considered safe today but a 512-bit one isn't. Use the chapter's experiment on trial division.

S3. Every job at minute zero

A platform team finds that hundreds of scheduled jobs run "every 15 minutes", "every 30 minutes" and "every hour", all at minute 0, and the database spikes every hour on the hour. Use gcd and lcm to explain the spike, and propose fixes.