首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

怎样求500的阶乘?解决办法

2012-02-13 
怎样求500的阶乘?有没有好的方法[解决办法]http://topic.csdn.net/u/20100209/17/72fbf49c-4bef-437a-8ea4

怎样求500的阶乘?
有没有好的方法

[解决办法]
http://topic.csdn.net/u/20100209/17/72fbf49c-4bef-437a-8ea4-da578de928fa.html
论坛热贴。
下面是我的版本

C/C++ code
#include <stdlib.h>#include <stdio.h>#include <string.h>#define SIZE 100000#define MAX 100000000class product{public:    product();    void mul(unsigned long long);    void print();private:    unsigned int v[SIZE];    int h;};product::product(){    memset(v,0,sizeof(int)*SIZE);    v[0] = 1;    h = 1;}void product::mul(unsigned long long x){    unsigned int tmp[SIZE];    unsigned long long m;    tmp[0] = 0;    for (int i = 0; i < h; i++)    {        m = v[i] * x;        tmp[i] += m % MAX;        tmp[i+1] = m / MAX;    }    if (tmp[h] > 0)    {        h++;    }    //printf ("%d %u\n", sizeof (m),tmp[0]);    for (int i = 0; i < h; i ++)    {        v[i] = tmp[i];    }}void product::print(){    for (int i = h - 1; i >=0; i--)    {        printf ("%09u\n",v[i]);    }    printf ("\n");}void print (char * str, int l){}int main(){    product p;    for (int i = 1; i < 100000; i++)    {        p.mul(i);    }    p.print();} 

热点排行