Yes, you’re right in how the different upper limits would affect the output from the `range`

function. However, from a mathematical standpoint, in this example not dividing `10`

by `9`

to see if it goes evenly won’t impact the outcome of your function.

In practice, we don’t really need to bother with any divisors which are more than halfway between `2`

and `x`

.

If we consider again my example where `x = 763`

, then to determine if this is prime we need to divide it by every positive integer between 2 and 762 to see if any of them go evenly, right? Wrong.

All prime numbers are a subset of another collection of numbers called *natural numbers*, and the set of natural numbers covers every positive integer value. So, `7`

, `6`

, and `3`

are natural numbers; `-2`

, `-12`

are not; and, just to be awkward, we can choose whether or not we want to include `0`

as part of the set.

We can therefore redefine prime numbers in terms of natural numbers: a prime number is a natural number that cannot be formed by multiplying two smaller natural numbers.

From this definition, we know that all of our divisors must be natural numbers - that is to say integers - and so we can’t do `763 / 6.104 = 125`

and use that to rule out 763 as a prime, as `6.104`

is not a natural number.

When we’re checking whether `x`

is prime, the smallest natural number that we need to check is `2`

so we do `763 / 2 = 381.5`

. From this we also know that `763 / 381.5 = 2`

.

What we know from this is that if we divide `x`

by any number larger than the halfway point - in this case `381.5`

- we are going to get an answer that is somewhere in between `1`

and `2`

. (e.g. `763 / 382 = 1.997382`

).

The point of our function is to see whether `x / n`

produces an integer output. If we know that any value of `n`

larger than `x / 2`

will never produce an integer output, because it’ll be “one and a bit” as shown above, then why bother calculating them?

Hopefully that makes sense. Yay for math!