To test whether a number is prime or not, why do we have to test whether it is divisible only up to the square root of that number?
Let's say m = sqrt(n)
then m × m = n
. Now if n
is not a prime then n
can be written as n = a × b
, so m × m = a × b
. Notice that m
is a real number whereas n
, a
and b
are natural numbers.
Now there can be 3 cases:
In all 3 cases, min(a, b) ≤ m
. Hence if we search till m
, we are bound to find at least one factor of n
, which is enough to show that n
is not prime.