Created
April 18, 2011 21:36
-
-
Save joeegan/926240 to your computer and use it in GitHub Desktop.
py1b.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import * | |
odd_numbers = []; | |
non_primes = []; | |
limit = 8000 # needs to be 8000 to calculate 1000th prime | |
i = 1 | |
while i <= limit: | |
i = i + 2 | |
odd_numbers.append(i) | |
for odd_number in odd_numbers: | |
divisor = 1 | |
while divisor < odd_number-1: | |
divisor = divisor + 1; | |
if odd_number % divisor == 0: | |
non_primes.append(odd_number) | |
break | |
primes_set = set(odd_numbers).difference(non_primes) | |
primes = list(primes_set) | |
primes.sort() | |
primes.insert(0,2) | |
print "Prime number 1000 is "+ str(primes[999]) | |
sum_of_logs = 0 | |
for prime in primes: | |
sum_of_logs = sum_of_logs + log(prime) | |
print "n is " + str(limit) | |
print "sum of the logs of the primes is " + str(sum_of_logs) | |
print "ratio of sum_of_logs:n is " + str(sum_of_logs/limit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment