yhlee: Alto clef and whole note (middle C). (Default)
yhlee ([personal profile] yhlee) wrote in [community profile] intro_to_cs 2009-11-12 08:18 pm (UTC)

For Problem 2:

def prime_product(n):
	# first prime, followed by other prime candidates
	number = 3
	
	# the sum of all primes so far, starting with lonesome 2
	sum = math.log(2)
	
	while number <= n:
		if is_prime(number) == 1:
			sum = sum + math.log(number)
		number = number + 2
	
	print "Sum of log of primes:", sum
	print "n: ", n
	print "Ratio of sum to n:", sum/n


I'm sure this is inefficient, but there it is. :-/

Post a comment in response:

This community only allows commenting by members. You may comment here if you're a member of intro_to_cs.
(will be screened if not on Access List)
(will be screened if not on Access List)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting