Implement matrix multiplication and fast exponentiation
WeRideSoftware Engineer · Technical ScreenLast updated
This question evaluates competency in matrix multiplication, modular arithmetic, and exponentiation algorithms as applied to large-scale numeric computations such as sequence generation.
1)
An × mBm × p
C = A × B``n × p
MODMOD
2) Exponentiation by Squaring
x k MOD
-
x^k -
x^k mod MOD -
O(log k) -
k = 0``x = 0
3)
n (n ≥ 0) n F(n)
-
F(0)=0, F(1)=1 -
F(n)=F(n-1)+F(n-2) -
2×2O(log n) -
MOD
/
multiply(A, B) -> Cpow(x, k, MOD=None) -> valuefib(n, MOD=None) -> value
n10^9DP
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.