package com.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class PLZUUtils {
    
    public static BigDecimal computePaiLie(int n, int m) {
        if(m > n || n < 0 || m < 0) {
            throw new IllegalArgumentException("n必须大于m!");
        }
        return computerJC(n).divide(computerJC(n - m), 1, RoundingMode.HALF_UP);
    }
    
    public static BigDecimal computeZuhe(int n, int m) {
        if(m > n || n < 0 || m < 0) {
            throw new IllegalArgumentException("n必须大于m!");
        }
        //=n!/m!(n-m)!
        
        return computerJC(n).divide((computerJC(m).multiply(computerJC(n - m)).setScale(1, RoundingMode.HALF_UP)), 1, RoundingMode.HALF_UP);
    }
    
    
    public static BigDecimal computerJC(int n) {
        if(n < 0) {
            throw new IllegalArgumentException("n不能为负数!");
        } else if(n == 0) {
            return new BigDecimal(1);
        }
        BigDecimal bd = new BigDecimal(1.0);
        for(int i=n; i>=1; i--) {
            bd = bd.multiply(new BigDecimal(i)).setScale(1, RoundingMode.HALF_UP);
        }
        return bd;
    }
    
    public static void main(String[] args) {
        BigDecimal zh = computeZuhe(462, 442);
        System.out.println(zh.doubleValue());
    }
    
}

 

 

相关文章:

  • 2021-12-29
  • 2021-08-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2021-07-07
  • 2021-11-30
  • 2022-12-23
  • 2021-10-29
相关资源
相似解决方案