A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

can u suggest an algorithm to check prime or not?

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    The 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 non-prime.

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    You 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.

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    see 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.

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I'm pretty sure you didn't mean an actual algorithm, but just in case: http://en.wikipedia.org/wiki/Primality_test#Fast_deterministic_tests

  5. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.