We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Period
You are viewing a single comment's thread. Return to all 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