| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1348 人关注过本帖
标题:求100!的解答。
只看楼主 加入收藏
cnfarer
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:179
帖 子:3330
专家分:21157
注 册:2010-1-19
收藏
得分:0 
回复 10楼 lpro
不是存不了那么大数,而是精度不够!

★★★★★为人民服务★★★★★
2010-03-06 18:12
shl305
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:36
专家分:121
注 册:2009-3-13
收藏
得分:1 
C++标准里没有超大整数的支持,要做的话可以用数组模拟,最简单的可以模拟小学时计算
乘法时的用的竖式
2010-03-07 02:10
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:1 
如果想省点事的话,可以找点大数库来算(而且一般大数库都自带阶乘的函数)。
比如可以算1000!
402387260077093773543702433923003985719374864210714632543799910429938512398
629020592044208486969404800479988610197196058631666872994808558901323829669
944590997424504087073759918823627727188732519779505950995276120874975462497
043601418278094646496291056393887437886487337119181045825783647849977012476
632889835955735432513185323958463075557409114262417474349347553428646576611
667797396668820291207379143853719588249808126867838374559731746136085379534
524221586593201928090878297308431392844403281231558611036976801357304216168
747609675871348312025478589320767169132448426236131412508780208000261683151
027341827977704784635868170164365024153691398281264810213092761244896359928
705114964975419909342221566832572080821333186116811553615836546984046708975
602900950537616475847728421889679646244945160765353408198901385442487984959
953319101723355556602139450399736280750137837615307127761926849034352625200
015888535147331611702103968175921510907788019393178114194545257223865541461
062892187960223838971476088506276862967146674697562911234082439208160153780
889893964518263243671616762179168909779911903754031274622289988005195444414
282012187361745992642956581746628302955570299024324153181617210465832036786
906117260158783520751516284225540265170483304226143974286933061690897968482
590125458327168226458066526769958652682272807075781391858178889652208164348
344825993266043367660176999612831860788386150279465955131156552036093988180
612138558600301435694527224206344631797460594682573103790084024432438465657
245014402821885252470935190620929023136493273497565513958720559654228749774
011413346962715422845862377387538230483865688976461927383814900140767310446
640259899490222221765904339901886018566526485061799702356193897017860040811
889729918311021171229845901641921068884387121855646124960798722908519296819
372388642614839657382291123125024186649353143970137428531926649875337218940
694281434118520158014123344828015051399694290153483077644569099073152433278
288269864602789864321139083506217095002597389863554277196742822248757586765
752344220207573630569498825087968928162753848863396909959826280956121450994
871701244516461260379029309120889086942028510640182154399457156805941872748
998094254742173582401063677404595741785160829230135358081840096996372524230
560855903700624271243416909004153690105933983835777939410970027753472000000
000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000

 
如果楼主是做留的练习作业,那么你们肯定是讲了有关大数乘法的知识。用起来就行了。
像楼上说的比较简单的算法。或者相对快一些的还有 Karatsuba Multiplication 算法之类的。
2010-03-07 09:35
chengwen1016
Rank: 2
等 级:论坛游民
帖 子:14
专家分:60
注 册:2010-3-6
收藏
得分:1 
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    long int a[256], b, d;
    int m, n, i, j, r;
    cin >> n;
    m = 1;
    m = log(n) * n/6 + 2;  //估算结果的位数
    memset(a, 0, sizeof(a));
    a[1] = 1;
    d = 0;
    for (i = 2; i <= n; i++)
    {// 算法核心
        for (j = 1; j <= m+5; j++)
        {
            b = a[j]*i + d;
            a[j] = b%1000000;
            d = b/1000000;
        }
      if (d > 0 ) a[j] = d;
    }
    for (i = m; i > 0; i--)
        if(a[i] == 0)
            continue;
        else
        {
            r = i;
            break;
        }
    cout << n << "!=";
    cout << a[r] << "  ";
    for (i = r-1; i >=1; i--)
    {
        if(a[i] > 99999) cout << a[i] << "  ";
        else if(a[i] <= 99999 && a[i] > 9999) cout << "0" << a[i] << "  ";
        else if(a[i] <= 9999 && a[i] > 999)   cout << "00" << a[i] << "  ";
        else if(a[i] <= 999 && a[i] > 99)     cout << "000" << a[i] << "  ";
        else if(a[i] <= 99 && a[i] > 9)       cout << "0000" << a[i] << "  ";
        else                                  cout << "00000" << a[i] << "  ";
    }
    cout << endl;
    return 0;
}
2010-03-07 18:44
shonjan
Rank: 1
等 级:新手上路
帖 子:12
专家分:7
注 册:2009-12-28
收藏
得分:1 
回复 13楼 pangding
强人!!!
2010-03-08 23:27
快速回复:求100!的解答。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020353 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved