Problem 2. Write a program that computes the sum of the logarithms of all the primes from 2 to some number n, and print out the sum of the logs of the primes, the number n, and the ratio of these two quantities. Test this for different values of n. My quastion : what base log they mean ? base of 10 ? e ?
you must be doing problem set 1 of MIT 6.00 OCW :-D they mean base e, so somewhere in your python script you must have the line import math (or even from math import * or from math import log) and then you must use math.log() function (or just log() if you used from math import * or from math import log)
ok, cheers !
if you use log(x[,base]) , then you can specify the base but default is e. if you use log10(x) , then base is 10 so you can use any of them because in question , the base is not specified.
Usually in programming log means base 2. But it doesn't matter much because logs of different bases only differ by a constant factor. \[\log_{b}a = \log(a) / \log(b)\]\[\log(a) = \log_{b}(a) / \log(b)\]So, for example, to convert between log base 10 and log base e:\[\log_{e}x = \log_{10}x / \log_{10}e\]you would just divide by log base 10 of e, which is a constant.
Join our real-time social learning platform and learn together with your friends!