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.
So essentially we're dealing with a finite integer field of 2^31.
So the key is to first test whether S, Q or P are coprime with 2^31.
If any of them are coprime that means the sequence will NOT repeat. Thus the result will be N.
Only go on after that check with the obvious algorithm of calculating the sequence and seeing when the sequence repeats. And you can stop as soon as you encounter a previously appearing number.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Bit Array
You are viewing a single comment's thread. Return to all comments →
So essentially we're dealing with a finite integer field of 2^31. So the key is to first test whether S, Q or P are coprime with 2^31. If any of them are coprime that means the sequence will NOT repeat. Thus the result will be N.
Only go on after that check with the obvious algorithm of calculating the sequence and seeing when the sequence repeats. And you can stop as soon as you encounter a previously appearing number.