Project Euler #122: Efficient exponentiation

  • + 1 comment

    Was having trouble with the use of brauer chain (wasn't sure brauer chain necessarily contains one of the shortest chains for every , but it satisfies the input contraint here). Implemented some sort of breadth first search with deque and got Runtime Error #2.

    With a bit of tweaking, I found that for certain input range there must be a shortest chain starting with [1, 2, 4, 8, 16], and some smaller range [1, 2, 4, 8]. This reduces the queue significantly. Then it passed. Smells like cheating.