He ain't no Ramanujan

Your friend has written a program to check whether or not a number n n is prime. It is very simple and works by checking if n n is divisible by each number from 2 all the way to n 1 n-1 . When you see this, you curse your friend and tell him he's wasting time.

If your friend didn't want to waste time, what is (approximately) the biggest number that he needs to check before he can determine that any number n n is prime?

n 2 n^2 n \sqrt{n} log n \log n n 4 \sqrt[4]{n}

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

5 solutions

It is just okay to check all the way up to n . \sqrt{n}.

Note that the factors occur in pairs ( a , b ) (a,b) where n = a b . n=ab.

Now, either a a or b b is less than or equal to n \sqrt{n} . If it were not, then their product would be greater than n n = n \sqrt{n} \cdot \sqrt{n}=n , and n a b . n\ne ab.

Thus, for every factor that is greater than or equal to n \sqrt{n} , there exists another factor which is less than or equal to n . \sqrt{n}.

Smart! And very clear explanation.

Vaishnavi Gupta - 6 years, 3 months ago

Log in to reply

let us assume that i want to check for 6. If i divide 6 by root 6 , i get root 6 then how do i know it's prime or not?

A Former Brilliant Member - 4 years, 10 months ago

Log in to reply

It turns out that 6 \sqrt{6} is not an integer, in fact it is 2.44949 2.44949 approximately. We only need to check the integral values below this to check whether 6 is a prime. In fact, the only number we need to check is 2, which immediately tells us that 6 is not a prime.

Agnishom Chattopadhyay - 4 years, 10 months ago

Log in to reply

@Agnishom Chattopadhyay then you should give the correct option as [ root n] where [.] represent the floor function

A Former Brilliant Member - 4 years, 10 months ago

Log in to reply

@A Former Brilliant Member I could. It seemed redundant to me, though

Agnishom Chattopadhyay - 4 years, 10 months ago
Chew-Seong Cheong
Jul 14, 2014

At first I thought it was 1 2 n \frac{1}{2}n , but no! It is actually n \sqrt{n} . If a number n n is not a prime, it can have two factors, say, a a and b b and n = a b n=ab . If both a > n a>\sqrt{n} and b > n b>\sqrt{n} , then a b > n ab>n . Therefore the largest factor should be n \boxed{\sqrt{n}} .

Not exactly, you should have said:

The largest factor is within n \sqrt{n}

Agnishom Chattopadhyay - 6 years, 11 months ago

Log in to reply

The largest factor is within n \sqrt{n}

Not exactly, you should have said:

For any factor pair of positive integer n, at least one element in the pair will be less than or equal to n \sqrt{n}

The largest factor of any integer n is n, and n \sqrt{n} < n

Flewk Isdead - 6 years, 9 months ago
Alex Whitton
Jul 30, 2014

In fact you should only need to check whether n is divisible by all prime numbers in 2 to sqrt(n) inclusive. Having said that - if you had a table of prime numbers available I guess you wouldn't need the programme in the first place! You could still speed it up by only checking for divisibility by 2 and all odd numbers in the range since all primes are odd except 2.

OR you can just try if it divisible on 2 - 3 - 5 - 7 if yes ,then it isn't prime if no , then it is prime

Ahmad Magdy - 6 years, 10 months ago

Log in to reply

What about 11,13,17,19,...

Pradyumna Datta - 6 years, 10 months ago

Log in to reply

yup, you are correct sorry for late response. It is not that late right :D

Ahmad Magdy - 4 years, 12 months ago

Is there something wrong with the above? I found it is quite true. Can someone explain thanks.

James Lewis - 5 years ago
Curtis Clement
Apr 29, 2015

If c = a b \ c= ab and WLOG a b \ a \leq b then a n \ a \leq\sqrt{n} therefore we only need to check factors up to n \sqrt{n} as it must contain a factor a {a} that is less than or equal to n {n}

Sam Cheung
Jul 14, 2014

It's called the Sieve of Eratosthenes .

Because all factors come in pairs (squares have a repeated factor), the largest factor you need to check is root n since one of the pair will be at most root n.

Moderator note:

It's not quite the same thing. This sieve cancels out multiples of the smallest prime less than n n , then cancels out multiples of the second smallest prime less than n n , and so on. Which is different from the search for all the whole numbers less than n \sqrt n .

Hmm... This is not the same thing

Agnishom Chattopadhyay - 6 years, 11 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...