Period of recurrence relation mod p

811 Views Asked by At

For a recurrence relation like $$f(n)=((k-2)*f(n-1)+(k-1)*f(n-2) )\bmod p$$ with initial conditions .This recurrence holds for n>=4 $$\begin{align}f(1)&=k \bmod p\\ f(2)&=k*(k-1) \bmod p\\f(3)&=k*(k-1)*(k-2) \bmod p\end{align}$$ where $p=10^9+7$, how will we find the period. The sequence will surely be periodic with period $\leqslant p^2$.

1

There are 1 best solutions below

10
On BEST ANSWER

Hint: For $n >1,$ $f(n)= (k-1)^{n}+(k-1) (-1)^n \mod p.$ Proof by induction.

Then for $k, (k-1,p)=1$ we have $$ f(p-1)=(k-1)^{p-1}+(k-1)=1+(k-1) \mod p=k =f(1). $$