I tried using type long in java it worked well. But, I want to handle values greater than long so I moved to BigInteger but ended up with an error with incompatible types(BigInteger and int). Thanks in advance.
import java.io.*;
import java.util.*;
import java.math.BigInteger;
class Main
{
public static BigInteger aryaStarkToWin(int p, int r,BigInteger[][]req_Array) {
BigInteger a=new BigInteger("1000000007");
BigInteger b=new BigInteger("0");
req_Array[p][0]=wins(p, 0, 0, p, r,req_Array) ;
BigInteger returnValue= req_Array[p][0];
returnValue=returnValue.mod(a);
return returnValue ;
}
public static BigInteger wins(int aryaCounter, int sansaCounter, BigInteger chances, final int p, final int r,BigInteger[][]req_Array) {
BigInteger a=new BigInteger("1000000007");
BigInteger b=new BigInteger("0");
BigInteger c=new BigInteger("1");
BigInteger d=new BigInteger("-1");
if(req_Array[aryaCounter][sansaCounter]!=d) {
return req_Array[aryaCounter][sansaCounter];
}
if (aryaCounter < sansaCounter * p) {
return b;
}
if (aryaCounter + sansaCounter == r) {
return c;
}
req_Array[aryaCounter][sansaCounter]=(wins(aryaCounter + 1, sansaCounter, chances, p, r,req_Array).mod(a).add(wins(aryaCounter, sansaCounter + 1, chances, p, r,req_Array).mod(a))).mod(a);
return req_Array[aryaCounter][sansaCounter];
}
public static void main(String[] args) {
int T_cases=0;
Scanner scany= new Scanner(System.in);
T_cases=scany.nextInt();
BigInteger d=new BigInteger("-1");
while(T_cases-->0) {
int no_of_rounds = scany.nextInt();
BigInteger[][] req_Array = new BigInteger[no_of_rounds+1][no_of_rounds+1];
int ptimes=scany.nextInt();
for(int i=0;i<=no_of_rounds;i++) {
for(int j=0;j<=no_of_rounds;j++) {
req_Array[i][j]=d;
}
}
System.out.println(aryaStarkToWin(ptimes,no_of_rounds,req_Array));
}
scany.close();
}
}
The input is
2
4 2
2 2
The output has to be
3
1
But, I'm getting error messages such as
Main.java:9: error: incompatible types: int cannot be converted to BigInteger
req_Array[p][0]=wins(p, 0, 0, p, r,req_Array) ;
1 error