Problems > Narayana's Cows Modulo > Editorial

Narayana's Cows Modulo — Solution & Editorial

Back to the Problem

Build the 3×3 companion matrix of the order-3 recurrence and exponentiate it in O(log N).

Complexity: O(log N)