Could someone take a look at my code for ps1b? Thanks.
Here is the solution I came up with. It works, but for numbers above 20,000 or so, it can take a little while to compute the answer. I was just wondering if there's a better/faster way to do it? from math import * n = input('Pick a number: ') sum = 0 for number in range(2,n): divisor = 2 while (divisor < (number/2)) and (number % divisor !=0): divisor = divisor + 1 if number % divisor != 0: prime_number = number sum = sum + log(prime_number) print sum + log(2) print n print (sum/n)
Here is all the code, highlighted with comments, if you need it: http://dpaste.com/hold/450061/
Last line, use this : print ((sum+log(2))/n) If not, you are not counting the log of 2 in your ratio and your theorem fails
Join our real-time social learning platform and learn together with your friends!