Template one:
#include <stdio.h>
#include <stdlib.h>
long long Combination(int n,int m)
{
long long nr = 1;
for (int j = 0; j < m; j++)
{
nr *= (n - j);
nr/=(j+1);
}
return nr;
}
int main()
{
int T,n, m;
scanf("%d",&T);
while (T--)
{
scanf("%d%d", &n, &m);
if (m>n/2)
m=n-m;
printf("%lld\n",Combination(n, m));
}
return 0;
}
Template two:
#include <stdio.h>
#define MAXN 100
long long bc[MAXN][MAXN];
long long binomial_coefficient(int n, int m)
{
int i, j;
for (i = 0; i <= n; i++)
bc[i][0] = 1;
for (j = 0; j <= n; j++)
bc[j][j] = 1;
for (i = 1; i <= n; i++)
for (j = 1; j < i; j++)
bc[i][j] = bc[i - 1][j - 1] + bc[i - 1][j];
return bc[n][m];
}
int main()
{
int T, n, m;
scanf("%d", &T);
while (T--)
{
scanf("%d%d", &n, &m);
if (m > n /2)
{
m = n - m;
}
printf("%lld\n", binomial_coefficient(n, m));
}
return 0;
}
Template three:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m;
const int p=10007;
int qpow(int a, int b)
{
int ans;
for(ans = 1; b; b >>= 1, a = a * a % p)
if(b & 1)
ans = ans * a % p;
return ans;
}
int getc(int n, int m)
{
if(n < m)
return 0;
if(m > n - m)
m = n - m;
ll s1 = 1, s2 = 1;
for(int i = 0; i < m; i++)
{
s1 = s1 * (n - i) % p;
s2 = s2 * (i + 1) % p;
}
return s1 * qpow(s2, p - 2) % p;
}
int lucas(int n, int m)
{
if(m == 0)
return 1;
return getc(n % p, m % p) * lucas(n / p, m / p) % p;
}
int main()
{
scanf("%d%d", &n, &m);
printf("%d\n", getc(n, m));
printf("%d\n", lucas(n, m));
return 0;
}