相关疑难解决方法(0)

用于计算阶乘的快速算法

我发现这个页面描述了许多用于计算阶乘的算法.不幸的是,解释很简洁,我不想逐行筛选源代码来理解算法背后的基本原理.

任何人都能指出我对这些(或其他快速)计算因子的算法的更详细描述吗?

编辑: 此页面描述了素数因子分解的方法,这是所有性能最佳的因子算法共有的技术.它还包含Python中的一些很好的示例代码.作者链接到二进制分裂的描述,并参考了算法杂志("计算因子的复杂性")中的一篇文章,看起来很有希望,如果我只能得到它.

algorithm performance factorial

23
推荐指数
2
解决办法
3万
查看次数

谁能解释这个算法用于计算大因子?

我遇到了以下计算大型因子(数字大到100)的程序..谁能解释一下这个算法中使用的基本思想?我只需要知道在计算阶乘时实现的数学.

#include <cmath>
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{

      unsigned int d;

      unsigned char *a;

      unsigned int j, n, q, z, t;

      int i,arr[101],f;

      double p;


    cin>>n;
    p = 0.0;
    for(j = 2; j <= n; j++)
        p += log10(j);
    d = (int)p + 1;
    a = new unsigned char[d];
    for (i = 1; i < d; i++)
        a[i] = 0; //initialize
    a[0] = 1;
    p = 0.0;
    for (j = 2; j <= n; j++) …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm factorial

22
推荐指数
1
解决办法
2871
查看次数

计算C中的大数因子

在我的C代码中,我想计算1到100范围内的数字的阶乘.对于小数字,该函数可以工作,但对于更大的数字,例如100!它返回不正确的结果.有什么方法可以处理C中的大数阶因子?我正在使用的编译器是gcc v4.3.3.我的代码如下:

#include <stdio.h>
#include <math.h>

double print_solution(int);

int main(void)
{
        int no_of_inputs,n ;

        int ctr = 1;

        scanf("%d",&no_of_inputs); //Read no of inputs

        do
        {
                scanf("%d",&n); //Read the input

                printf("%.0f\n",print_solution(n));

                ctr++;  

        }while(ctr <= no_of_inputs);


        return 0;       
}

double print_solution(int n)
{
        if(n == 0 || n == 1)
                return 1;
        else
                return n*print_solution(n-1);


}
Run Code Online (Sandbox Code Playgroud)

c algorithm

19
推荐指数
6
解决办法
5万
查看次数

16
推荐指数
6
解决办法
2万
查看次数

用于计算大因子的商的C++程序

如何编写c ++程序来计算大因子.

例如,如果我想计算(100!)/(99!),我们知道答案是100,但如果我分别计算分子和分母的阶乘,那么这两个数字都是巨大的.

c++

9
推荐指数
3
解决办法
7257
查看次数

如何计算因子?

说有一个计算阶乘(n)的函数

factorial(7)是否为1到7中的每一个创建了7个函数对象

并在必要时使用这些值(对于阶乘(8)像阶乘(7)*8)

factorial function-object

2
推荐指数
1
解决办法
856
查看次数

无法在C中使用阶乘函数

我无法使用以下代码.

#include <stdio.h>

// I am not sure whethere I should void here or not.
int main() {
    // when the first bug is solved, I put here arg[0]. It should be
    // similar command line parameter as args[0] in Java.
    int a=3;                  
    int b; 
    b = factorial(a);

    // bug seems to be here, since the %1i seems to work only in fprintf
    printf("%1i", b);
    return 0;      
}  

int factorial(int x) {
    int i; 
    for(i=1; i<x; i++) 
        x *= i; …
Run Code Online (Sandbox Code Playgroud)

c factorial

0
推荐指数
2
解决办法
3482
查看次数

标签 统计

factorial ×5

algorithm ×4

c ×2

c++ ×2

function-object ×1

performance ×1

recursion ×1