Initialize result matrix and unity matrix
for i in range ( 1 , K + 1 ) : NEW_LINE INDENT for j in range ( 1 , K + 1 ) : NEW_LINE INDENT if ( i == j ) : NEW_LINE INDENT result [ i ] [ j ] = 1 NEW_LINE DEDENT DEDENT DEDENT while ( n > 0 ) : NEW_LINE INDENT if ( n % 2 == 1 ) : NEW_LINE INDENT mul_1 ( K ) NEW_LINE DEDENT mul_2 ( K ) NEW_LINE n //= 2 NEW_LINE DEDENT