anonymous
  • anonymous
hey can anyone help me out with problem set 1, i dont where to begin writting code to print the first 1000th prime numbers....i dont want the answer just a understanding of how u get it
MIT 6.00 Intro Computer Science (OCW)
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
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.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

anonymous
  • anonymous
Ok, try defining the problem in terms of discrete tasks. The first thing you will need to be able to do is identify if a given number is a prime. Write a small piece of code that takes a variable N and checks to see if N is prime. If you run into trouble, ask here and be sure to use a pastebin site (dpaste.com is a nice one) to supply the code you're working with. Once you can identify if a given number is prime, you simply need to iterate all the natural numbers, checking each of them in turn, and if they are prime print them out until you have printed 1000 numbers.
anonymous
  • anonymous
thnkz alot and thanks for the site...i really appreciate it...i think a bell just rang off as i was thinking, could the code be something like: if n is divisible by only 1 and itself print n, if not continue...i hope it something to that sort. Now i just gotta find a way for the program to keep count of every prime...as u can see im kinda of a newbie so, any more tips would be of help, but thnkz already
anonymous
  • anonymous
Hi I think you're on the right track... just realized that thinking in discrete tasks isn't easy but it's definitely a good way to approach a problem. hmmm... well... one of the ps1 suggestions was to ensure that the numbers that you use to divide and test the prime-candidate should be as limited as possible. so, instead of dividing from 2 to n, one of the earlier threads talked about looking at http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes. I haven't tried using it yet but it seems pretty good.

Looking for something else?

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

More answers

anonymous
  • anonymous
write a module which will can test a given number being prime or not... checking prime number is fairly easy....i'm writing in c, so that you have to rewrite it in python bool is_prime(unsigned int num){ for(i=2;i<=num/2;i++){ if(num%i==0){ count++; break; } } if(count==0) return true; else return false; } next you have to start from 1 and check every number by passing that number into your prime number checker module, like this... unsigned int count = 0,i = 1; while(count < 1000){ if(is_prime(i)) count++; printf("%d",i); i++; }
anonymous
  • anonymous
thnkz alot everyone, wen i finally get the code ill post it

Looking for something else?

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