A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 4 years ago

I am working on ps1:#1. I have been banging me head against the wall for some time now trying to figure it out. It seems that the simplest way to find a prime number is to take your test (n%n-1) and check for remainder == 0. This way you can differentiate between prime and not prime numbers. However, I cannot seem to get things to work right in python, and now I feel that this may not even be an accurate way to calculate prime numbers (deterministically). I would greatly appreciate some pointers in the right direction on how to get this assignment to work. Thanks in advance.

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

    are you online?

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

    yes, I am

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

    go to chat

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

    looking around, not seeing a chat icon. are we already in chat?

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

    it should be at the bottom of the page.

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

    http://codepad.org/irXZYVQJ

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

    The way I approached calculating if a number is prime was to make sure that you cannot represent the number as a combination of prime factors rather than going through all the numbers smaller than itself. eg. 36 = 2^2 * 3^2 -So if we start with list primes [2,3], the next obvious number to check if its a prime is 5 (first odd number) - I check if 5 is divisible by 2 or 3, if not then it is a prime and I add to list of primes = [2,3,5] - I then check the next odd number 7, which is also prime as it is not divisible by 2, 3 or 5, so primes = [2,3,5,7] - Then I check 9, which is divisible by 3, I skip and go to 11 and so on. This way you go through a much smaller list of numbers each time http://codepad.org/G52Va8xf

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

    Thanks for your response! I actually figured it out for the most part. Went a slightly different route and was getting some strange print outputs regardless of correct prime values. I will take a look at yours and compare the two. Thanks again.

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