ProgrammingVery hard
A 2 x 2 matrix is raised to the power 10^18 by repeated squaring. How many squaring steps are needed?
- A. 60
- B. 18
- C. 10^18
- 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
- Which statement about the nested loop for (i = 0; i < n; i++) for (j = 1; j < n; j = 2) is correct?
- Which operation is O(1) in a C array, but O(n) in a singly linked list when the head is given?
- A program reads a number n and then loops for (i = 0; i < n; i++) with n = 10^9 and a constant body. Roughly how long does it take in C…
- Which operation makes a sorted array of n elements support lookup in O(log n) and insertion in O(n)?
- For a char buffer of length 10^6 that is processed once, which loop is correct and fast enough?
- A matrix of 3000 x 3000 cells is read once and each cell is visited a constant number of times. Which complexity bound applies to the…