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.
- Prepare
- C++
- Other Concepts
- Bit Array
- Discussions
Bit Array
Bit Array
Sort by
recency
|
309 Discussions
|
Please Login in order to post a comment
hey brothers, can anyone clarify the question please, I'm not understand what they mentioned in this problem, I'm so confused
Stupid optimization preferences. =( I had to study Knut on the subject of RNG - maybe I don't know something, How else to guarantee the uniqueness of a given sequence or its not going beyond N. I couldn't meet the time limit in one test case. It turned out that the compiler there did not want to optimize human-readable expressions.
Here is Bit Array solution in c++ - https://programmingoneonone.com/hackerrank-bit-array-solution-in-cpp.html
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.
Disclamer: a bit upset with the problem statement this pseudocode tells us that the sequence is actually linear(arithmetical) and (mathematecaly) unbounded from the top. so there is no use of Q%(2<<30) except once so the sequence is a = p*a+q there is no chance to repeate the value except overflow but we do not know what data type we should use for the sequence and it is machine specific. as the result: the solution
} debuged on test case 8 worked for my local PC for unsigned long but for HackerRank envirement only for unsigned int