zoukankan      html  css  js  c++  java
  • nyoj24大数阶乘

    大数阶乘

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:3
     
    描述
    我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?
     
    输入
    输入一个整数m(0<m<=5000)
    输出
    输出m的阶乘,并在输出结束之后输入一个换行符
    样例输入
    50
    样例输出
    30414093201713378043612608166064768844377641568960512000000000000
    View Code
     
    #include<stdio.h>
    #include<string.h>
    #define MAXN 20000
    int str[MAXN];
    int main()
    {
        int m,i,j,c,s;
        scanf("%d",&m);
        memset(str,0,sizeof(str));
        str[0]=1;c=0;
        for(i=2;i<=m;i++)
        {
            for(j=0;j<MAXN;j++)
            {
                s=c+str[j]*i;
                str[j]=s%10;
                c=s/10;
                if(c==0)
                continue;
            }
        }
        for(i=MAXN-1;i>=0;i--)
            if(str[i])break;
            for(j=i;j>=0;j--)
                printf("%d",str[j]);
        printf("\n");
        return 0;
    }
    
    
    
    
            
  • 相关阅读:
    Hashmap实现原理
    策略模式
    Google Drive ubuntu
    numix Docky
    Google Drive 和 Dropbox 同步同一个文件夹目录
    sublime text 2
    matlab cell
    liteide
    taglist and nerdtree
    codeblocks
  • 原文地址:https://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_2012_06_280.html
Copyright © 2011-2022 走看看