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

I have been working through the ps1a and ps1b questions and am slowly getting there but i am not sure what is being asked in 1b i have the sum of the logs but i don't understand the ratio part. Here is what i have so far http://ideone.com/F8uXP

OpenStudy (anonymous):

Ratio is just the division of a quantity by another. If I recall correctly, you should divide the sum of log ( logprime1 + logprime2 ... ) by the log of the sum ( log ( prime1 + prime2 + prime 3 + ... + prime1000 ) ) But I don't remember exactly what are the order to divide. Check the pset pdf, should be clear there.

OpenStudy (anonymous):

Let's take a simple case to understand the computation. Suppose we are trying to find the 10th prime number. The 10th prime number is: 29 The series is : [2,3,5,7,11,13,17,19,23,29] Logsum = log(2)+log(3)+...log(29) N=29 The ratio is: Logsum/N Your output should look like below. Notice as N increases the ratio converges to 1: @hich prime number do you want me to find: 10 The 10th prime is: 29 The ratio of LogSum/N is: 0.79659379841 >>> >>> Which prime number do you want me to find: 100 The 100th prime is: 541 The ratio of LogSum/N is: 0.935909535582 >>> >>> Which prime number do you want me to find: 1000 The 1000th prime is: 7919 The ratio of LogSum/N is: 0.986588504402

OpenStudy (anonymous):

Thank you both here is my updated code any comments welcome but it works so i am happy http://ideone.com/Niwzs

OpenStudy (anonymous):

Malpaso, For some reason, my ratios are somewhat different than yours. here's my code for the ratio: def sumlogprimeratio(x): z = 2 a = 0 b = 0 while z <= x: n = 2 while z%n != 0: n = n + 1 if n == z: a = z b = b + log(a) z +=1 print b/x Any thoughts on why that is?

OpenStudy (anonymous):

My understanding of the assignment was that the ratio is between the sum of the logs of the primes smaller then or equal to the number 'n', and the number 'n'. If I'm not mistaken, the number 'n' is not necessarily prime. Am I right? For example: Say the number 'n' chosen is 15. The primes up to n would be: 2,3,5,7,11,13 So, it should do (log2 + log 3+ log 5 + log 7 + log 11 + log 13)/15 Right?

OpenStudy (anonymous):

@Efarias. That's correct. n is the number that you are counting up to. But as the numbers get large the ratio will come out approximately the same whether you use, for example, 13 or 15.

OpenStudy (anonymous):

@EFarias. Let me check.

OpenStudy (anonymous):

@EFarias. Your code checks and the ratio is also correct. I will explain tomorrow why there is a discrepancy in our results. There isn't a real discrepancy. You did a good job and have gotten the correct result.

OpenStudy (anonymous):

@malpaso. That´s good news! Looking forward to your explanation! Thanks!

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!