Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

paul99santos

  • 2 years ago

Assignment #1 Computing Prime Numbers Hi, I made a program from Assignment #1 Computing Primes Number, I don't know if there is any better program than this? Source code->http://pastebin.com/91Y5WEnL The Source Code: ------------------------------------------------------------------ for candiPrimes in range(2,410): #Test Primes Numbers from 2 to 410 divisor = 1 NumOfReTimes = 0 #Count how many remainder 0 will show up while (divisor<=candiPrimes): '''Analogy: Numbers start from 2 / N times if two remainder 0 will show up and the number is Prime''' if candiPrimes % divisor == 0: NumOfReTimes += 1 divisor += 1 if NumOfReTimes == 2: #test if two remainder 0 did show up print ' ' + str(candiPrimes), -----------------------------------------------------------------

  • This Question is Open
  1. VirPriscus
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I've run it, and it does what it's supposed to, namely, produce prime numbers less than 410.

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

    My question is there any efficient or better source code than this?

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

    The only real improvement I can think of is that you don't need divisor to come all the way up to candiPrime. You only really need to go up to the sqrt of candiPrime.

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

    Please post your source code to http://pastebin.com and copy/paste you're URL here.

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

    http://dpaste.com/750733/

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

    Search OpenStudy
    • Attachments:

Ask your own question

Ask a Question
Find 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
  • 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.