Created
May 27, 2017 13:45
-
-
Save Kaushal28/429b7671c76acbea9637b8e734361d26 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.math.*; | |
class GFG { | |
public static BigInteger binomial(int n, int k){ | |
if(n < k){ | |
return new BigInteger("0"); | |
} | |
BigInteger dp[][] = new BigInteger[n+1][n+1]; | |
for(int i=0;i<=n;i++){ | |
for(int j=0;j<=n;j++){ | |
if(j == 0 || i == 0 || i == j){ | |
dp[i][j] = new BigInteger("1"); | |
} else if(i<j){ | |
dp[i][j] = (new BigInteger("0")).subtract(new BigInteger("1")); | |
} else{ | |
dp[i][j] = dp[i-1][j].add(dp[i-1][j-1]); | |
} | |
} | |
} | |
return dp[n][k].mod(new BigInteger("1000000007")); | |
} | |
public static void main (String[] args) { | |
Scanner in = new Scanner(System.in); | |
int t = in.nextInt(); | |
while(t-->0){ | |
int n = in.nextInt(); | |
int k = in.nextInt(); | |
System.out.println(binomial(n,k)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why did you write "mod(new BigInteger("1000000007")" in return statement?