anonymous
  • anonymous
can u suggest an algorithm to check prime or not?
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
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.
anonymous
  • anonymous
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.
anonymous
  • anonymous
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.

Looking for something else?

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

More answers

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

Looking for something else?

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