I've been trying to write a test function for Fibonacci pseudo-primes with large $n$. Fibonacci pseudoprimes are composite numbers such that $V_n(P,Q) \equiv P \mod n$ for $P>0$ and $Q =\pm 1$, with $V_n$ Lucas sequence.
As such I need to compute Lucas sequence for large $n$. They are defined by:
$U_n(P,Q)=\frac{a^n-b^n}{a-b}$ et $V_n(P,Q)=a^n+b^n$ with $a,b=(P\pm \sqrt{P^2-4Q})/2$
Direct computation is not possible because I need to work with integers and $\sqrt{P^2-4Q}$ may not be one.
There are also binomial formulations of the form $U_n(P,Q)=2^{1-n}\sum_{k=0}^{\lfloor (n-1)/2 \rfloor}\binom{n}{2k+1}P^{n-2k-1}(P^2-4Q)^k$. But computing $U_n$ that way seems to be $O(n^2)$ which is not acceptable for me.
Are there any ways to compute $U_n$ and $V_n$ in $O(1)$ or $O(\log n)$ which involve only integers and not floating point ?
Thanks in advance