I’m getting correct answers for test case but wrong answer on submitting the code.
here is my code
import java.util.*;
import java.io.*;
public class Main {
static int mod = 98765431;
static long[][] multiply(long a[][], long b[][]){
int row = a.length;
int col = b[0].length;
long c[][] = new long[row][col];
for(int i=0; i<row; i++){
for(int j=0; j<col; j++){
for(int k=0; k<row; k++)
c[i][j] = ( c[i][j]%mod + ( (a[i][k] % mod) * (b[k][j] % mod) )%mod )%mod;
}
}
return c;
}
static long[][] pow(long T[][], long n){
if(n==1)
return T;
long p[][] = multiply(T, T);
if(n%2 == 0)
return pow(p, n/2);
else
return multiply(T,pow(p, n/2));
}
public static void main(String args[]) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String nt[] = br.readLine().split(" ");
int n = Integer.parseInt(nt[0]);
long t = Long.parseLong(nt[1]);
long c[][] = new long[n][1];
for(int i=0; i<n; i++){
c[i][0] = Long.parseLong(br.readLine());
}
long T[][] = new long[n][n]; // creating a coefficient matrix
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(i!=j) // except diagonal all other elements are 1
T[i][j] = 1;
}
}
T = pow(T, t);
T = multiply(T,c);
for(int i=0; i<n; i++)
System.out.println(T[i][0]);
}
}