如何用多循环解此问?

问题描述
将 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 分解成五个正整数的和,有多少种分解方法?
我想使用多重循环而不使用数组,有什么办法解决吗?我尝试写了个代码可结果为1。
答案是691677274345

public class main {
    public static void main(String[] args) {
        int num =0;
        for (int x=1;x<=2021;x++){

            for (int x1=1;x<=2021;x++){

                for (int x2=1;x<=2021;x++){

                    for (int x3=1;x<=2021;x++){

                        for (int x4=1;x<=2021;x++){
                            if(x+x1+x2+x3+x4==2021){
                                num++;
                            }
                        }
                    }
                }
            }
        }
        System.out.println(num);
    }
}

“该回答引用ChatGPT”
还请参考下面的方案,如果可行还望点击 采纳,感谢:

使用递归函数可以解决这个问题。首先,我们定义一个函数,每次递归时选择一个数并对剩余的数继续调用该函数,直到我们选择了 5 个数。然后,我们可以检查它们是否和等于 2021,如果是,则统计答案。

int count = 0;
void decompose(int n, int count, int sum) {
    if (count == 5) {
        if (sum == 2021) {
            count++;
        }
        return;
    }
    for (int i = 1; i <= n; i++) {
        decompose(n - i, count + 1, sum + i);
    }
}
int main() {
    decompose(2021, 0, 0);
    printf("答案是:%d", count);
    return 0;
}