include stdio int gcd int int return gcd int solve int int int 20 int

 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
#include <stdio.h>
int gcd (int a, int b) { return b?gcd(b,a%b):a; }
int solve(int n, int k)
{
int a[20];
int counter1,counter2,d,g,res;
if (k>(n/2)) k=n-k;
for (counter1=0; counter1<k; counter1++)
a[counter1] = n-counter1;
for (counter2=2; counter2<=k; counter2++)
for (counter1=0, d=counter2; d>1; counter1++)
{
g = gcd(a[counter1],d);
a[counter1] /= g;
d /= g;
}
for (counter1=0, res=1; counter1<k; res*=a[counter1++]);
return res;
}
int main()
{
int n,k;
while (scanf("%d %d",&n,&k)==2 && (n || k))
{
printf("%d\n", solve(n,k));
}
return 0;
}