全RE 呜呜呜 求助
查看原帖
全RE 呜呜呜 求助
244544
魏翠云楼主2020/5/4 07:46

RE了 聚聚们求救啊!

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] a = new int[n][n];
		int k=sc.nextInt();
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[0].length; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		qp(a, k);
	}

	static void qp(int[][] a,int n) {
		int mod=4399;
		int[][] ans=new int[a.length][a.length];
		for (int i = 0; i < a.length; i++) {
			ans[i][i]=1;
		}
		while (n>0) {
			if ((n&1)==1) {
				ans=mult(ans, a, mod);
			}
			a=mult(a, a, mod);
			n>>=1;
		}
		for(int[] one:ans) {
			for(int data:one) {
				System.out.print(data+" ");
			}
			System.out.println();
		}
	}
	static int[][] mult(int[][] a, int[][] b, int mod) {
		if (a[0].length != b.length) {
			return null;
		}
		int[][] res = new int[a.length][b[0].length];
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < b[0].length; j++) {
				for (int k = 0; k < b.length; k++) {
					res[i][j] = (res[i][j] + a[i][k] * b[k][j] % mod) % mod;
				}
			}
		}
		return res;
	}
}

2020/5/4 07:46
加载中...