What tool are yu guys using to get the 1000th prime? As in, i understand HOW to determine if a number is prime, but how are yu specifying which prime number yu want? Thank you.
Can you share your code so far?
Use nested while loops. Have a counter tick off each prime found(initialize counter=1, then use while counter <1000). That is the outer loop. Within that loop, generate candidate numbers starting with 3(initialize n=3) and count by twos, since only odd numbers are can be prime. Use an inner while loop to test each number generated to see if it is prime. When you get a prime, tick off the counter (counter=counter+1). When counter gets to 999 you have your 1000th, since you didn't originally count 2. But the loop won't terminate until after you generated one extra n+2, so you need to print n-2. Tinker around with all the handout examples and they will give you everything you need. Insert print commands in your code to debug or use handwritten charts.
assign value of prime number to some x in the end of the loop.This is way when the loop stops you should write print x and get answer
you can use a counter to do this, but the way I approached it was to create a list of primes starting with [2,3] and add on additional primes as you test for them, then keep doing so with a while loop till the length of the list Primes reaches 1000. I replied to a previous post with the following, hopefully it applies. By storing the prime numbers you can then go one to use them for subsequent loops so you don't have to test every single number up to the root. 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
use assignment statement like x=primeNumber(assuming u've already found it)
haha bluepig, I HAVE no code yet. Im trying to brainstorm how id go about doing this...like, what tools to use and such. i think i have a well enough idea. i actually havent looked at the handout yet so i think i should probably continue with that. thanks everyone!
Join our real-time social learning platform and learn together with your friends!