trial division is bounded

 15th March 2024 at 1:52pm

I'll argue that, during trial division (checking whether nn is a prime, for example) it is not necessary to test if nn is divisible by n1n-1, or n2n -2, down to a given number.

Suppose 17, for example (a prime). Using xy x \nmid y to mean x does not divide y, and testing whether 17 is divisible by numbers between 1 and 17, suppose we get to 8; and we realise 817 8 \nmid 17 ; naturally we would test 917 9 \mid 17 .

But if 9 divided 17, that would imply 17=9k,kN 17 = 9 * k, k \in \mathbb{N} . This follows from the definition of division. To be divisible (loosely) means that a given number can be expressed as a product of two other numbers. But the least possible value of kk is 2, and 92=18>17 9 * 2 = 18 > 17, and so we conclude no number bigger than 8 can be a divisor to 17 — this, together with knowning no number up to 8 divides 17, means 17 is a prime number.

A possible upper bound for checking division of primes could be n/2n / 2, but, in fact, the best bound is sqrt(n)sqrt(n); the reason why is left as an exercise.