• + 0 comments

    For people who already solved it, the idea used here is useful for finding period in many other similar recurrent sequences, such as Fibonacci numbers. Notice that, for any such sequence modulo p, the order is at most p^2. So first you need to find M such that the sequence surely repeats after a[M]. And if it is periodic, then you will also see that the order is a divisor of this M