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.
made numerous edits. my question is this ... when setting the range for the divisor to check a primes, what is the end limit... 'n'? n/2? our candidate prime?
Technically, the square root of the number
# is there a functional way to do this? in part 1a, where i wrote the 1000th prime finder, i used a FOR loop.. for divisor in range (2, (candidate/2)): # and this was how i was able to test a range of divisors to identify a prime is it the same concept (given that i am not using a square-root function?
I think you are trying too hard, let me help you understand. You have done problem 1, correct? Please show you your code for number 1 and, for the sake of simplicity and efficiency, replace your "n/2" by "math.sqrt(n)+1" Then I'll build from that code to get the next problem done =D
Basically, you need a MINOR modification from code 1 to get code 2 working
## here is my code for part 1a: prime_count = 1 candidate = 2 not_one_if_true = 0 while prime_count < 1000: if candidate%2 == 0: # to eliminate even nnumbers candidate += 1 else: for divisor in range(2,(candidate/2)): # find divisor range if candidate%divisor == 0: # find primes not_one_if_true = 1 # if not prime if not_one_if_true == 0: if prime, increment prime_count += 1 candidate +=1 else: # if not a prime, increment, reset Boolean truth candidate += 1 not_one_if_true = 0 print candidate - 1
That code seems to have a problem. Maybe use pastebin, because there seem to be problems.
# i forgot to comment out a note... i just ran this newly pasted code and got 7919 # don't know how to use pastebin... prime_count = 1 candidate = 2 not_one_if_true = 0 while prime_count < 1000: if candidate%2 == 0: # to eliminate even nnumbers candidate += 1 else: for divisor in range(2,(candidate/2)): # find divisor range if candidate%divisor == 0: # find primes not_one_if_true = 1 # if not prime if not_one_if_true == 0: #if prime, increment prime_count += 1 candidate +=1 else: # if not a prime, increment, reset Boolean truth candidate += 1 not_one_if_true = 0 print candidate - 1
Okay, here is the easy part. I made your code work for problem 2, but I will not show it. Create a variable named Sum. Every time you find a prime number, add the math.log of that number to Sum. Answer is 7803
If you come close to 7803, tell me. I will tell you why you may be a "little" off
Okay. Remember this. 1) You must NOT count the math.log of the last number ( 7919 ). This is said in the assignment. It has to be all numbers BELOW the nth prime. Is your answer now exact?
so i set my limit too high (1000), instead of 999... thanks for the help!
Your answer is wrong. Do you count the math.log(2) somewhere in your code?
no, i couldn't figure that part out... my code can be broken down into 1. determine if odd; if even, increment by one 2. if odd, determine if there are factors within range (2 to n/2) [is it prime] 3. if prime, increment by one, and add for part 1b, also add sum = math.log(candidate) + sum but since i am eliminating the even in my initial code, i don't have the math.log(2) incorporated
Then add math.log(2) somewhere in the code. The exact answer is near 7803.3
will do, thanks!