-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathprog4.java
More file actions
49 lines (40 loc) · 1.2 KB
/
prog4.java
File metadata and controls
49 lines (40 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static long choose(long n,long k){
//System.out.println("n-1 = " +n + "n-k = "+k);
long res = 1;
// Since C(n, k) = C(n, n-k)
if ( k > n - k )
k = n - k;
// Calculate value of [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
for (int i = 0; i < k; ++i)
{
res *= (n - i);
res /= (i + 1);
}
return res;
}
public static void main (String[] args) throws IOException
{
// your code goes here
//BufferedReader br = new BufferedReader ( new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
// String [] inp = br.readLine().split(" ");
long n = sc.nextLong();
long k = sc.nextLong();
// System.out.println(" n= "+n+" k= "+k);
if(n<=k) System.out.println(1);
else{
System.out.println(choose(n-1,n-k));
}
}
sc.close();
}
}