Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we check up to the square root of a prime number to determine if it is prime?

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?

like image 984
Pan Avatar asked Apr 27 '11 22:04

Pan


People also ask

Does a prime number have a square root?

Sal proves that the square root of any prime number must be an irrational number. For example, because of this proof we can quickly determine that √3, √5, √7, or √11 are irrational numbers.

What is the purpose of prime factorization Why do we need to do prime factorization?

Prime factorization is one of the methods used to find the Greatest Common Factor (GCF) of a given set of numbers. GCF by prime factorization is useful for larger numbers for which listing all the factors is time-consuming.

How do you efficiently determine if a number is prime?

The simplest primality test is trial division: given an input number, n, check whether it is evenly divisible by any prime number between 2 and √n (i.e. that the division leaves no remainder). If so, then n is composite. Otherwise, it is prime.


2 Answers

If a number n is not a prime, it can be factored into two factors a and b:

n = a * b 

Now a and b can't be both greater than the square root of n, since then the product a * b would be greater than sqrt(n) * sqrt(n) = n. So in any factorization of n, at least one of the factors must be smaller than the square root of n, and if we can't find any factors less than or equal to the square root, n must be a prime.

like image 53
Sven Marnach Avatar answered Sep 28 '22 02:09

Sven Marnach


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:

  1. a > m ⇒ b < m
  2. a = m ⇒ b = m
  3. a < m ⇒ b > m

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.

like image 42
BiGYaN Avatar answered Sep 28 '22 02:09

BiGYaN