Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 20 Online
OpenStudy (anonymous):

In PS 1 I can easily generate integers but I can't separate primes from rest of integers.... Any clues?

OpenStudy (anonymous):

Read carefully pseudo-code in problem set. Wikipedia: "A natural number is called a prime number (or a prime) if it is bigger than one and has no divisors other than 1 and itself." Only odd integers are candidate for prime numbers. Pseudo-code for that you have in the problem set. When you do that, you have candidates for prime numbers. Your next step should be to check if the number is prime. Example: Your number is 5. It's a odd number, so it's your candidate for prime. Next: you check if that number (5) is divisible with 2,3,4. We see it isn't, so the number 5 is prime.

OpenStudy (anonymous):

"""Example: Your number is 5. It's a odd number, so it's your candidate for prime. Next: you check if that number (5) is divisible with 2,3,4. We see it isn't, so the number 5 is prime.""" When I write divisible in this sentence I mean that the number has no divisors other than 1 and itself.

OpenStudy (anonymous):

Note that when people say "divisible" they really mean "divides into evenly, with a remainder of zero". (Recall the x%a formula from lecture 2 and 3). Now as candidate numbers prove to be primes, you need to add them to "collections" of primes. See lecture 3.

OpenStudy (anonymous):

and once it passes the test, you need to record that it is the nth prime number so far, incrementing by 1 each time a candidate passes the test.

OpenStudy (anonymous):

that's what i already knew guys... i actually wanted exact code that can get me through

OpenStudy (anonymous):

there are plenty of working codes here in the study group, I don't see the value in giving the answer outright and deny you the aha! moment when you figure it out yourself. Someone else might though.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Arriyanalol: So on this pretty tuesday we loss a beautiful soul dolly parton
1 hour ago 1 Reply 0 Medals
Mari103: How to pop out like a Jacc In the box
22 hours ago 0 Replies 0 Medals
Breathless: Spooky witch but cute
1 day ago 3 Replies 0 Medals
Arriyanalol: help
1 day ago 10 Replies 2 Medals
Arriyanalol: @tinydinoUwU stop trying to find a argument u blad lil boy
2 days ago 5 Replies 4 Medals
Jaded012023: Please tell me what you all think of this song
1 day ago 6 Replies 1 Medal
Arriyanalol: bro how
1 day ago 2 Replies 3 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!