for ps1b: http://dpaste.com/564911/ i tried to just use the program i made for ps1a with modifications, but i'm kind of stuck. can someone point me in the right direction? :)
I think the problem may be line 25. Are you sure you want to add log(2) each time? Shouldn't it be the log(current prime number)?
the code was executing the same even without line 25, which was added later because i realized i needed to include log(2) in my sum. i don't see how it would be executing each time anyways as it's outside my loop.
Which is correct: I don't see the need for the log(2) line anyway. I believe it should be covered in the previous line when you wrote prime_c = prime_c + 2. I think it's because you didn't actually start at 2 for your first prime. You said that this was your modification to your answer for ps1a. Lots of people finds it convenient (me included) to skip 2, 3 and even 5 for that prime number problem. And rightly so. But modifying this for the second problem would be troublesome because of the skipped primes. See for example your initial divider. 2 can't possibly be divided be 3, couldn't it?
Wait a minute. Did you actually test your solution for ps1a? Did it work correctly?
Yes that does work correctly. I think I know what the problem is now. Thanks everyone for your help!
well the problem is your code includes 1 as a prime number...the logarithm sum is absolutely correct...and the second thing is u need to get the ratio of log sums and the last prime number... that shud be nearly 1 :) for proof..check these codes out..the first one is a modified version of ur code.. and the second is mine http://dpaste.com/hold/565013/ http://dpaste.com/hold/565016/
@ Lifeburner ..his code actually includes 3,5 and 7 :)
The problem is asking for the sum of the logs of all the primes less than n. NOT the sum of the logs of the first n primes. So for n = 10 the primes would be: 2,3,5,7. NOT 2,3,5,7,11,13,17,19,23,29
yea n everybody seems to get the problem wrong..but my code above is computing sum of the logs of all the primes less than n :)
ya, my answer was pretty bad:( just kind of glanced at your code first thing this morning while half asleep...
I just woke up..and i am still half asleep.. ;) there is no place like bed...[yawn]
Sunu, I'm not sure I get your answer. In line 10 you say "while x > y:". But x will always be equal to y since you already gave them values in the first few lines and they haven't changed.
For that there is a x=x+2 in line 18.. sorry actually i have been too lazy to comment in my codes...from now on i'll try to comment..:(
bwCA, i caught that. stupid mistake on my part. it's running fine now :)
Join our real-time social learning platform and learn together with your friends!