Eratosthenes and the Linear Sieve
In short: to find every prime up to n, don't test each number on its
own — strike out multiples instead. Starting from each prime p, cross off
p·p, p·p+p, p·p+2p, … up to n; anything never crossed off is prime. That's
the Sieve of Eratosthenes, and it costs O(n log log n). A sharper version,
the linear sieve, strikes every composite exactly once — each composite
is crossed off only by its smallest prime factor — and costs O(n). Quarry's
hash kernel needs this: prime bucket counts, prime moduli and quick
factorisation all start with "which numbers up to n are prime".

Picking a bucket count that resists clustering
Quarry's hash table spreads keys across capacity buckets with
hash(key) % capacity. Pick capacity = 100 and every key that's a multiple
of 10 — user ids 10, 20, 30, … — lands in buckets 0, 20, 40, …: a fifth of
the buckets, used by everything. A prime capacity breaks that pattern,
because a prime shares no common factor with any key except 1.
97 keys hashed into a 97-bucket table land in 97 different buckets, no matter what the key pattern is — because 97 has no factor in common with 10. Pick table sizes from a prime list, not round numbers.