Skip to content

Instantly share code, notes, and snippets.

@TheNilesh
Created July 16, 2017 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheNilesh/3e3c970f32bbbbafe98f2406dce1e014 to your computer and use it in GitHub Desktop.
Save TheNilesh/3e3c970f32bbbbafe98f2406dce1e014 to your computer and use it in GitHub Desktop.
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int count = scanner.nextInt();
for (int i = 0; i < count; i++) {
int N = scanner.nextInt(); /*Number of 0's*/
int M = scanner.nextInt(); /*Number of 1's*/
System.out.println( nCr(N + M - 1, N) );
}
}
public static int nCr(int n, int r) {
return factorial(n) / (factorial(n - r) * factorial(r));
}
public static int factorial(int n) {
if (n == 1 || n == 0) {
return 1;
}
return n * factorial(n - 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment