问题描述
因此,数的阶乘由以下n!= n *(n-1)*(n-2)..(n-n)给出。我在C中实现如下:
unsigned int factorial(int n) {
unsigned int product = 1;
for(int i = n; i > 0; i--) {
product *= i;
}
return product;
}
然后排列如下:
我在C中实现了以下目标:
// Given the example of p(5,3) => 5!/3! which is the same as 5*4,that is how I implemented this below
unsigned int permutation(int N,int n) {
int temp = N-n;
unsigned int product = 1;
for(int i = N; i > temp; i--) { // only compute values from N * (N-1)... (N-n) based on the prevIoUs math above
product *= i;
}
return product;
}
组合如下所示,其中k是上述表示法中的r:
我在C中实现了以下目标:
int combination(int N,int n) {
unsigned int temp = permutation(N,n);
unsigned int product = factorial(n);
return temp / product;
}
我遇到的问题是我正在尝试采用nCr(31,24)= 2629575的组合,在我的C代码中它应与permuation(31,24)/ factorial(24)相同等于1.6315x10 ^ 30 / 6.2044x10 ^ 23 =2629575。但是我想得到整数重载,因为我的permutation(31,24)返回1279262720,而factorial(24)返回3519021056。如何计算组合和大量的排列?有没有办法在C中为析因和置换存储大量内存?最后,我的小TI-30XS计算器可以很好地处理这些计算,最多可以存储1e99的数字,怎么存储呢?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)