If i have a recursive sequence $a_1=4$ and $a_{n}=a_{n-1}^{2}-2$ in $\mathbb{Z}_{M_{n}}$ where $M_n=2^n-1$
how i can calculate the complexity time of this sequence ? if we put it in the loop for n-1 iteration .
pseudocode :
S=4; i=2;
While($i<n$,
$S=S^2-2 (\mod M_n)$
If( S==0 then Break[]);
);
im not sure that overall complexity is $O(log^3(M_n))$