anonymous
  • anonymous
I'm struggling with the sum of the logs problem in Problem Set 1. My ratio seems to approach 0, and very slowly. I'm not getting the output I expected from reading the problem.
MIT 6.00 Intro Computer Science (OCW)
jamiebookeater
  • jamiebookeater
See more answers at brainly.com
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.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

anonymous
  • anonymous
from math import * n = 10 oddinteger = 3 checkdigit = 2 primecount = 1 primelogsum = log(2) while n < 10000: while primecount < n: if oddinteger%checkdigit == 0: oddinteger += 2 checkdigit = 2 elif oddinteger%checkdigit != 0 and checkdigit*2 < oddinteger: checkdigit += 1 else: primecount += 1 primelogsum += log(oddinteger) oddinteger += 2 checkdigit = 2 print "Sum of the logs of the primes: " + str(primelogsum) print "n: " + str(n) print "Ratio of sum of the logs of the primes to the value n: " + str(float(primelogsum)/float(n)) print "" primelogsum = log(2) n += 10
anonymous
  • anonymous
what does n represent and what is it meant to be doing?
anonymous
  • anonymous
Well, I'm a moron. I was operating under the assumption that: as n increases - primelogsum approaches 1. when it now seems that I need to keep taking the sum of the logs each time I get a new prime number, and that ratio will approach 1.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
while leaving n as a constant
anonymous
  • anonymous
actually now that I read it again, I think I was right - n is supposed to increase with each iteration. I set it to some value, then add up all the logs of prime numbers up to n, divide that result by n, and then increase n and have another iteration.
anonymous
  • anonymous
Are you actually adding up ALL the logs? Why does primelogsum keep getting reset to log(2)?
anonymous
  • anonymous
I'm doing that each time the while primecount < n condition becomes false, which begs the question, why do I care whether my primecount is < n? I should be checking my oddinteger that is being tested for primeness against n.
anonymous
  • anonymous
... and we're approaching 1 on a squiggly line :-)
anonymous
  • anonymous
cool!
anonymous
  • anonymous
Thanks for the help!

Looking for something else?

Not the answer you are looking for? Search for more explanations.