A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
can u suggest an algorithm to check prime or not?
anonymous
 5 years ago
can u suggest an algorithm to check prime or not?

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0The fundamental task in looking for prime numbers is to confirm that your candidate is not a multiple of any prime number less than itself. To accomplish this, you can either keep a list of the prime numbers you find, and check each candidate for candidate % prime for each prime you have found. If you can't find a prime for which candidate % prime == 0, then candidate is a prime. A somewhat simpler (perhaps) solution would be to check each candidate against the numbers smaller than itself and see if any of them divide your candidate. If so then it must have a prime factor and is therefore nonprime.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0You would check the number from 2 to the square root of the number you are trying to decide if it is prime or not. If any of them divide evenly (most programs have a mod type function which returns the remainder of a division problem) then it is not prime. No reason to check past the square root of the number.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0see that a prime number yields a remainder 0 only when it is divide by itself and 1.so make a variable to count how many numbers yields a remanider 0 when the given number is divided by a series of numbers.if the variable count is 2 then it is a prime.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I'm pretty sure you didn't mean an actual algorithm, but just in case: http://en.wikipedia.org/wiki/Primality_test#Fast_deterministic_tests
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.