Gave up on the generator model. Consolidated the main logic into one function to allow me to add some cycle detection. If we find a cycle, we can compute the nth element of m without having to iterate any further