Data Structures & AlgorithmsHardCodeforces Div2 D · matrix power

Problem: What is the complexity of computing the n-th Fibonacci number modulo a prime p using matrix exponentiation?

  1. A. O(log n) matrix multiplications
  2. B. O(n) additions
  3. C. O(sqrt n)
  4. D. O(n log n)

Correct answer: A. O(log n) matrix multiplications

Exponentiation by squaring needs O(log n) multiplications of constant-size 2 x 2 matrices.

More Coding Interview Problems questions

Exams that ask this topic