Powers of square matrices X39269


Statement
 

pdf   zip

html

Write a program that, given a square matrix M and a natural number n, computes Mn.

Input

The input consists of several cases. Each case consists of a natural number n ≥ 0 followed by a natural number m > 0 and by m × m integer numbers.

Output

For each case, print the elements of Mn in m lines following the format of the example. Print a line with 10 dashes after every matrix.

Public test cases
  • Input

    2 4
    1 -2 3 4
    2 3 4 -5
    -3 4 5 6
    4 5 -6 7
    3 4
    1 -2 3 4
    2 3 4 -5
    -3 4 5 6
    4 5 -6 7
    

    Output

    4 24 -14 60
    -24 -4 68 -18
    14 68 -4 40
    60 18 -40 4
    ----------
    334 308 -322 232
    -308 218 360 206
    322 360 54 -28
    232 -206 28 -62
    ----------
    
  • Information
    Author
    Gabriel Valiente
    Language
    English
    Translator
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    Unknown.
    User solutions