UVa 10229 - Modular Fibonacci

Solving this problem requires you to calculate Fibonacci in lg(n) time. It's by dividing n into n/2 size at each instance. Another tweak which can be used in this problem was to store Fibonacci upto 10^6(mod 2^m) where m is maximum modulus. To find Fn(mod 2^k) where k <m, use this formula that

((fib(n)%t + (1<<m)%t)%t)%t where t is 2^k. It is based on fact that if a number n is stored some modulus k and u want to know num%m where m < k. Then, it's given by

 (n%m + k%m)%m Italic text