Primality test bound: square root of n

3.4k Views Asked by At

I was reading about primality test and at the wikipedia page it said that we just have to test the divisors of $n$ from $2$ to $\sqrt n$, but look at this number:

$$7551935939 = 35099 \cdot 215161$$

Since $\sqrt {7551935939} \approx 86901,875$ so basically I would only have to check the divisors from $2$ to $90000$, but one of the divisors ($215161$) is greater than $90000$.

Also, do you guys have some ideas to improme my primality test?

2

There are 2 best solutions below

1
On BEST ANSWER

Once you find the smaller divisor, you automatically find the larger divisor too.

0
On

It's already been implicitly said by several people, but here is the explicit reasoning. Suppose that $n$ is not prime. Then we can write $n = ab$ for integers $a$ and $b$ which are both greater than $1.$ If both $a > \sqrt{n}$ and $b > \sqrt{n}$ then we would have $ab > \sqrt{n}\sqrt{n} = n,$ a contradiction. Hence either $a \leq \sqrt{n}$ or $b \leq \sqrt{n},$ so if you check as far as $\sqrt{n}$ and don't find a divisor of $n$ greater than $1,$ then $n$ must be prime.