ProgrammingVery hard

A 2 x 2 matrix is raised to the power 10^18 by repeated squaring. How many squaring steps are needed?

  1. A. 60
  2. B. 18
  3. C. 10^18
  4. D. 59

Correct answer: D. 59

The exponent has 60 bits, so the loop squares the matrix at most 59 times. This gives O(log n) matrix products.

More C Programming questions

Exams that ask this topic