Efficient exponentiation
I like this problem. It is a very good problem.
I tried it with different approaches. First, I found that Knuth has given a very fast algorithm to find out the most efficient way of doing exponentiation. I followed his idea, and find an answer, but Project Euler rejected it. Then I used a brute force tree method to solve it. It is solved, but very slow, and cost a lot of memory.
I learned from the discussion thread. I found this is a very difficult math problem and there is no algorithm ready for use. So the optimal solution is still kind of brute force. But it is critical to reduce the search space. I learned how to do it in C++. But I am not satisfied with what I learned. It is slower than hk's solution(now admin of PE). For example, if I changed the number 200 to 6000, it takes my code 80s to find the answer. hk's solution only needs 17s(several years ago). Since I am not familiar with Delphi, I gave up. If you understood what he was doing, please leave me a comment.
No comments:
Post a Comment