Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 19 Online
OpenStudy (traveler4):

Hi I'm having a problem with problem set 2 part 2. The sum of the natural logs of my primes is always greater than n. And as n gets larger the difference gets more substantial. For example when n is 1000, the sum of the natural logs of the primes is 7002. This isn't just a problem with my code. I tried manually typing some into my calculator and it was still way off. Is anyone else having this problem? If not can anyone confirm that the sum of the natural logs of each of the primes is supposed to be about equal to n?

OpenStudy (rsmith6559):

FWIW, here's my code from the Fall 2008 course. The prime numbers are in a list called primes logTotal = 0 for i in xrange( 0, len( primes ) ): logTotal += math.log( primes[i] ) print "\nThe sum of the logs is:", logTotal print "The largest prime:", lastPrime print "The ratio of them is:", lastPrime / logTotal

OpenStudy (anonymous):

I'm not sure I quite understand your issue... but the way I set this problem up, I used basically 3 variables: 1st variable as a counter (n), so that I could see what prime number I was on, 2nd variable as the prime number (x), 3rd variable as the sum of the logs of the primes (q), kindof. (and there was one more as an 'escape variable' for my loop but w/e). So for the 1st prime number n = 1, x = 2, q = 0 (for the first one, but log(x) = 0.69314718056) and the sum of the logs divided by the prime number or ((log(x)+q)/(x)) = 0.34657359028 2nd prime number n = 2, x = 3, q ((0+log(2)) = 0.69314718056, and the sum of the logs divided by the prime number or ((log(x)+q)/(x)) = 0.597253156409 3rd prime number n = 3, x = 5, q (now 0 + log(2) + log(3)) = 1.79175946923, and the sum of the logs divided by the prime number or ((log(x)+q)/(x)) = 0.680239476332 4th prime number n = 4, x = 7, q (now 0 + log(2) + log(3) +log(5)) = 3.40119738166, and the sum of the logs divided by the prime number or ((log(x)+q)/(x)) = 0.763872504388 And like the assignment says, the higher n goes the closer that last quantity gets to 1. I hope that helped?

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!