Divisibility comparison between factorials
This problem is not quite interesting. But from this problem, I realize that learning something is more important than just solving some problems!
I have been reviewing all my solved problems recently, and after I learned something from an old problem, I realized that I should give this problem a shot.
Since the problem asks n < 10^18, we can not check each number. The first thing is to find an equivalent problem that can be relatively easy solved. If you say you cannot find it, I would recommend you to review all problem between 140 and 150 and read TAOCP volume 1, 1.2.6 exercise.
The second thing is to solve this relatively easy problem. I should admit that the logic is still not so straight forward to be translated into code. I spent quite some time debugging n=100 and n=1000 until I found that I have some logic error. After that, the problem is solved with in 1 ms!
No comments:
Post a Comment