A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing


  • one year ago

the problem is to 'Write a program that computes and prints the 1000th prime number.' on python. This is highschool level and we only write really basic code, no advanced operations. The hint said to start by generating odd numbers. I only got this much so far, and I'm really stuck and need assistance, please! count=0 i=2 while count !=1000: if (i%2!=0) (that basically narrows it down to odd numbers) @jabez177 @jabez177

  • This Question is Open
  1. mathmate
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    There is a very useful piece of information when you find prime numbers by the sieve of Eratosthenes. 1. You only have to test divisibility of prime numbers. For example, after a number is tested not divisible by 2 then it would not be divisible by 4,6,8... 2. You only have to test divisibility of primes up to and including the square-root of the highest number you need to test. In this case, the maximum number is 1000, so you need only to test all primes up to sqrt(1000)=31, which means testing for divisibility of 2,3,5,7....31 only. If a number below 1000 is not divisible by ALL the listed primes, the number itself is prime. In your code, the loop is not working well. If you use a while loop, you need a starting value (2), the stopping value (>1000, not !=1000) and an increment (either 1 or 2). Make some adjustments and run your code. Then post us the code and tell us what you get out of your code, and where you think the error might be, if any.

  2. rsmith6559
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    First, take a deep breath. This isn't a huge assignment, and it's not a bad choice for this point in a high school class. The first thing that you need to do is figure out what you'll need to do this. mathmate has mentioned that you may want to keep the primes that you've found around for later checks, so you'll need data structure to read/write the primes to, you'll need code to check "primeness" of a number, and a counter to know when you've gotten to 1000. When in doubt, break the problem into smaller parts. Sooner or later, the parts will be small enough that the code to do the part will become apparent.

  3. mathmate
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yes, I've misread the question. If you need the 1000th prime, you need to store around 100 primes for divisibility checks. This can be done simply with arrays, if you have already done arrays. You would then test divisibility until the size of the square-root of the prospective prime. Let's say you are testing the number 5273 for primality, you can stop at sqrt(5273)=72.6. That means after testing for divisibility of 71, you don't need to test divisibility of 73. As your course goes on, you will be learning more tools that you'll need. So don't get overwhelmed. Almost everyone who has done programming has gone through this.

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


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