์‹ค๋ฒ„1 : ๋ถ„ํ•  ์ •๋ณต ๋ฌธ์ œ์ด๋‹ค.

์ƒ๊ฐ

ํŠน์ • ํ–‰๋ ฌ์„ 10๋ฒˆ ๊ณฑํ•˜๋ผ๋Š” ์˜๋ฏธ๋Š”, ๊ณง ์ด๋ ‡๊ฒŒ ํ•ด์„ ๋œ๋‹ค.

\\begin{align} A^10 & = A^2 \times A^5 \\ &= A^2 \times A^2 \times A^3 \\ &= A^2 \times A^2 \times A^2 \times A \\ \\end{align}

๊ฒฐ๊ตญ, 10์ด๋ผ๋Š” ์ˆซ์ž๊ฐ€ ๋“ค์–ด์™”์„ ๋•Œ, 2๋กœ ๋‚˜๋ˆ„์–ด์ง€๋ฉด A๋ฅผ ์ œ๊ณฑํ•˜๊ณ  ans์— ์—…๋ฐ์ดํŠธ, ๋‚˜๋ˆ„์–ด์ง€์ง€ ์•Š์œผ๋ฉด A๋ฅผ ํ•œ๋ฒˆ ๊ณฑํ•˜๊ณ , A์ œ๊ณฑ์„ ๊ณฑํ•˜์—ฌ ์—…๋ฐ์ดํŠธ ํ•œ๋‹ค.

typedef vector<vector<int>> matrix;
 
matrix operator * (const matrix &a, const matrix &b) {
    int n = int(a.size());
    matrix ans(n, vector<int>(n));
 
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                ans[i][j] += a[i][k] * b[k][j];
            }
            ans[i][j] %= 1000;
        }
    }
    return ans;
}
matrix go(matrix a, long long b){
    int n = int(a.size());
    matrix ans(n, vector<int>(n));
 
    if (b == 0) return ans;
    if (b % 2) ans = ans * a;
    return ans * go(a*a, b/2);
}
int main(){
    int n;
    long long b;
    cin >> n >> b;
 
    matrix a(n, vector<int>(n));
 
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> a[i][j];
 
    matrix ans == calc(a, b);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << ans[i][j] << ' ';
        }cout << '\n';
    }
}

Reference