思路:高精度来求
代码:
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int n,k;
while(scan.hasNext()){//求最小值min
n=scan.nextInt();
k=scan.nextInt();
if(n-k<=k) k=n-k;
BigInteger ans=new BigInteger("1");
BigInteger max=new BigInteger("1000000000000000000");
BigInteger tmp=new BigInteger("1");
int m=n;
for (int i=1;i<=k;i++){
tmp=BigInteger.valueOf(i);
ans=ans.multiply(BigInteger.valueOf(m));
ans=ans.divide(tmp);
if (ans.compareTo(max)>=0)
break;
m--;
}
if (ans.compareTo(max)>=0) System.out.println(max);
else System.out.println(ans);
}
}
}
?
|