1.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem 369 - Combinations
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=5&problem=305
*
* @author Miesel Christoph
* @author Seilbeck Robert
* @author Wolfram Andre
*
*
* Status : Accepted
* Runtime: 0.348
*/
public class Main {

public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
String line;
while ((line = reader.readLine()) != null) {
StringTokenizer token = new StringTokenizer(line);
int N = Integer.parseInt(token.nextToken());
int M = Integer.parseInt(token.nextToken());
BigInteger result = new BigInteger("1");
if (N == 0 && M == 0) {
break;
}
if (N == M || M == 0) {

} else {

int NM = N - M;
BigInteger numerator = new BigInteger("1");
BigInteger denumerator = new BigInteger("1");
if (NM > M) {
for (int i = N; i > NM; i--) {
numerator = numerator.multiply(new BigInteger(i + ""));
}
for (int i = 2; i <= M; i++) {
denumerator = denumerator.multiply(new BigInteger(i
+ ""));
}
} else {
for (int i = N; i > M; i--) {
numerator = numerator.multiply(new BigInteger(i + ""));
}
for (int i = 2; i <= NM; i++) {
denumerator = denumerator.multiply(new BigInteger(i
+ ""));
}
}
result = numerator.divide(denumerator);
}
System.out.println(N + " things taken " + M + " at a time is " + result
+ " exactly.");
}
}
}

2.


/**
 * Angewandte Mathematik, SS09, IFB 2C 
 * ACM Problem: Combinations (369)
 * @author Christian Mitterreiter
 * @author Rolf Luigs
 * @version 1.0, 06/11/2009
 * Status : Accepted
 * Runtime: 1.416
 */

import java.math.BigDecimal;
import java.util.Scanner;

public class Main {


    public static BigDecimal fak(BigDecimal f, BigDecimal s) {  //Fakultšt berechnen
        if (f.compareTo(s) < 0) return BigDecimal.ONE;
        else return f.multiply(fak(f.subtract(BigDecimal.ONE), s));   
    }

   
    public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        BigDecimal m,n,c,r,s,t,u;
           
            while(true)    {
                //Einlesen der Zahlen
                n = sc.nextBigDecimal();
                m = sc.nextBigDecimal();
               
                if(n.equals(BigDecimal.ZERO) && m.equals(BigDecimal.ZERO)) break;  //Abbruchbedingung
               
                //Formel, wie auf Angabenblatt berechnen
                s = fak(n, BigDecimal.ONE);
                t = fak(m, BigDecimal.ONE);
                r = n.subtract(m);
                u = fak(r, BigDecimal.ONE);
                c = s.divide((u.multiply(t)));
               
                //Ausgabe
                System.out.println(n + " things taken " + m + " at a time is " + c + " exactly.");
            }
    }
}