Monday, April 26, 2010

5 & 6 down, 293 to go

Prob 5: Very cool problem, because the short solution (9 lines) was fast up to about first 10 integers (find lcm), then it became much slower. The long solution was not measurably slower for first 30 integers than for the first 10. If the problem had been first 30 integers, I would have had to have used the longer algorithm, but the short one gets the job done for n = 20.

Big insight on this problem was actually something that would have been a cooler solution for prob 3 -- start with 2 and just divide if you can, then change the target divisor to n/2 and repeat until you can't anymore, then move to 3 and then 4. What's cool about this is that it will pick up all the factors of 2, thus knocking out all the composite even numbers. Repeat until the number you're dividing by equals the number you've reduced your target to. Not only are you done, but (by the Sieve of Aristophanes), the last divisor is the largest prime.

Not much interesting in Prob 6. Not sure why it came after 4 & 5.

1 comment:

  1. Just redid problem #3 to use the loop algorithm -- Hella faster. How do you write that in Big(O) notation?

    ReplyDelete