1.
import java.util.Scanner;
/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 369 - Combinations
* Link:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=305
*
* @author Siegfried Ippisch
* @version 1.0
*
* Method : -
* Status : Accepted
* Runtime: 0.684
*/
public class Combinations {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
long n = in.nextLong();
long m = in.nextLong();
while(n != 0 || m != 0){
System.out.printf("%d things taken %d at a time is %d
exactly.\n",n,m,f(n,m));
n = in.nextLong();
m = in.nextLong();
}
in.close();
}
public static int f(long n, long m){
double res = 1;
for(long i=0; i<m; i++){
res = res * (n-i);
res = res / (i+1);
}
return (int)(res+0.5);
}
}
2.
package acm_369_combinations;
import java.util.Scanner;
/**
* FWP, Ausgew¦hlte Probleme aus dem ACM Programming Contest, SS10
* Problem: acm_369_combinations
* 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.780
*/
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.printf("%d things taken %d at a time is %d exactly.%n",n, m, (int) (b+0.001));
return true;
}
}