借鉴同学田先生方法
Java刷题-----蓝桥杯省赛JavaC组第十二届(第二场)4-------------6_CLODVEP的博客-CSDN博客
题目:
本题总分:15 分
问题描述
将 3 分解成两个正整数的和,有两种分解方法,分别是 3 = 1 + 2 和 3 = 2 + 1 。注意顺序不同算不同的方法。
将 5 分解成三个正整数的和,有 6 种分解方法,它们是 1 + 1 + 3 = 1 + 2 + 2 = 1 + 3 + 1 = 2 + 1 + 2 = 2 + 2 + 1 = 3 + 1 + 1。
请问,将 2021 分解成五个正整数的和,有多少种分解方法?
答案提交
这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。
分析:
3分解成2个数子的合,有两种方法,
5分成3个数字的和,有6中,想到了高中学的组合公式
经过实验题目给出的两个数字都减1然后带入公式就可以找出所有组合的可能性
比如题目给定的2021分成5个数字,那么n=2020,r=4,然后根据公式求就可以了。
由于数字太大所以需要biginterger来做,则需要里面的sub,div,mu分别是减,除,乘

步骤:

package 第十二届省赛第二套;
import java.math.BigInteger;
import java.util.Scanner;
public class 整数分节 {
public static void main(String[] args) {
BigInteger b1 = new BigInteger("2020");
BigInteger b2 = new BigInteger("2020");
BigInteger b3 = new BigInteger("1");
BigInteger b4 = new BigInteger("1");
while (!b1.equals(b3)) {
b1=b1.subtract(b4);
b2 = b2.multiply(b1);
}
BigInteger y1 = new BigInteger("4");
BigInteger y2 = new BigInteger("4");
BigInteger y3 = new BigInteger("1");
BigInteger y4 = new BigInteger("1");
while (!y1.equals(y3)) {
y1=y1.subtract(y4);
y2 = y2.multiply(y1);
}
BigInteger z1 = new BigInteger("2016");
BigInteger z2 = new BigInteger("2016");
BigInteger z3 = new BigInteger("1");
BigInteger z4 = new BigInteger("1");
while (!z1.equals(z3)) {
z1=z1.subtract(z4);
z2 = z2.multiply(z1);
}
BigInteger cheng = new BigInteger("0");
BigInteger divide = new BigInteger("0");
cheng = y2.multiply(z2);
divide = b2.divide(cheng);
System.out.println(divide);
}
}