The qualification round of the Facebook Hacker Cup was held last weekend, and in the last problem you had to calculate the values of a vector according to this recursive relation (for some given values of a, b, c and r):
$m(0) = a\\ m(i) = (b \cdot m(i - 1) + c) \bmod r$
After programming a trivial solution for the problem I could see there was a pattern. For instance, for this test case:
a: 6, b: 30, c: 524, r: 98
The vector was:
[[18, 84, 6, 18, 84, 6, 18, 84, 6,...
How can I calculate the period of the pattern? (Do not worry, the qualif. round ended and this won't give me additional points or anything, it's just out of curiosity ;)