TITLE: fibonacci series mod a number
QUESTION [10 upvotes]: I'm trying to write a program with an input of numbers $n$ and $k$ (where $n<10^{1000}$ and $k<10^9$), where I compute fib[n] % k.
What is a good FAST way of computing this? 
I realize that the resulting series is periodic, just not sure how to find it efficiently.

REPLY [3 votes]: Perhaps Elsenhans, Jahnel, "The Fibonacci sequence modulo $p^2$ –
An investigation by computer for $p < 10^{14}$" http://www.uni-math.gwdg.de/tschinkel/gauss/Fibon.pdf  will be interesting for you. There are sections about the algorithm.