Hacker News new | ask | show | jobs
by mkl 3089 days ago
It looks like step 4 should say something like (edited):

If b evenly divides a×r_i, where r_i is the current value, divide by b. If not, add or subtract p until the result is evenly divisible by b, then divide by b.

And step 6 should loop back to step 4 and define r_i to be the "result".

This method is very interesting and systematic, but it seems pretty complicated compared to ad hoc reasoning. E.g. 34 is a multiple of 17, so 680 must be too; 986-680 = 306, which is 34 away from 340, a multiple of 17, so 17 is a factor of 986.

2 comments

Yes, a step was missing. I've updated it to include multiplication by "a" and loop back to step 4.

And yes, this is more complex than basic reasoning. It's an optimization to the original algorithm, and like most optimized algorithms, is less transparent.

Yeah I was thinking one of the steps after the first one should probably mention a. :P The example clarified, but it looks like the steps might be both simpler and more clear by writing the formulas for each step.