第十二届省赛——5整数分解(高中组合公式)

借鉴同学田先生方法

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);
        
        
    }

}
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

W少年没有乌托邦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值