1.

/**
* Angewandte Mathematik, SS11
* Problem: 530 - Binomial Showdown
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=7&page=show_problem&problem=471
*
* @author Markus Schöllner
* @author Andreas Maier
* @version 1.0, 06/10/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.160
*/

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n,k, result, ggT;

n = input.nextInt();
k = input.nextInt();

while (true) {
result = 1;
if (n == 0 && k == 0)
break;

if(k > n/2) k = n-k;
else k = k;

int fac[] = new int[k];

for (int c = 0; c < k; c++) fac[c] = n - c;

for (int j = 2, denum = 2, i = 0; j <= k; i = 0, j++, denum = j)
while (denum > 1) {
ggT = ggT(fac[i], denum);
fac[i++] /= ggT;
denum = denum / ggT;
}

for (int c = 0; c < k; c++) result = result *fac[c];
System.out.println(result);

n = input.nextInt();
k = input.nextInt();
}
}

public static int ggT(int i, int denum) {
if(denum == 0) return i;
else return ggT(denum, i % denum);
}
}

----------------------------------------------------------------------------------------


1.
import java.util.Scanner;

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 530 - Binomial Showdown
* Link: http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=471
*
* @author Siegfried Ippisch
* @version 1.0
*
* Method : -
* Status : Accepted
* Runtime: 0.132
*/
public class BinomialShowdown {

public static void main(String[] args){
Scanner in = new Scanner(System.in);

int n = in.nextInt();
int k = in.nextInt();

while(n != 0){
System.out.println(f(n,k));
n = in.nextInt();
k = in.nextInt();
}

in.close();
}

public static int f(int n, int k){
k = Math.min(k, n-k);
double res = 1;
for(int i=0; i<k; i++){
res = res * (n-i);
res = res / (i+1);
}
return (int)(res+0.5);
}

}


2.

package acm_530_binomial_showdown;

import java.util.Scanner;

/**
 * FWP, Ausgew¦hlte Probleme aus dem ACM Programming Contest, SS10
 * Problem: acm_530_binomial_showdown
 * Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&page=show_problem&problem=305&Itemid=8
 *
 * @author Martin Lambeck
 * @version 1.0, 18.08.2010
 *
 * Method : adhoc
 * Status : Accepted
 * Runtime: 0.112
 */


public class Main
{
    static Scanner sc = new Scanner(System.in);

    public static void main(String... args)
    {
        while (testcase())
            ;
    }

    public static boolean testcase()
    {
       
        int n = sc.nextInt();
        int m = sc.nextInt();

        if ((n == 0) && (m==0))
            return false;
       
        double b = 1.0;
       
        double mi = 1.0;
        int ni = n;
       
        int mmax = Math.min(m, n-m);
       
        for (int i = 0; i < mmax; i++)
        {
            double v = ni / mi;
           
            b *= v;
           
            ni--;
            mi++;
        }

        System.out.println((int) (b+0.001));
        //System.out.printf("%d things taken %d at a time is %d exactly.%n",n, m, (int) (b+0.001));

        return true;
    }
}


3.

import java.util.Scanner;

/**
* Angewandte Mathematik, SS11
* Problem: 530 Binomial Showdown
* Link: http://uva.onlinejudge.org/external/5/530.pdf
* @author Brielbeck, Daniel
* @author Weber, Georg
* @version 1.0, 05/02/2011
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.144
*/

public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);

while (true) {
int n = in.nextInt(), r = in.nextInt();

if (n == 0 && r == 0)
break;
System.out.printf("%d\n", nCr(n, r));
}
}

public static int gcd(int a, int b) {
return b != 0 ? gcd(b, a % b) : a;
}

public static long nCr(int n, int r) {
int ans = 1;
r = r > n / 2 ? n - r : r;
int fac[] = new int[r];

for (int i = 0; i < r; i++)
fac[i] = n - i;

for (int j = 2, denum = 2, i = 0; j <= r; i = 0, j++, denum = j)
while (denum > 1) {
int gcd = gcd(fac[i], denum);
fac[i++] /= gcd;
denum /= gcd;
}

for (int i = 0; i < r; i++) {
ans *= fac[i];
}

return ans;
}
}