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

    http://acm.nyist.net/JudgeOnline/problem.php?pid=28

    大数阶乘

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:3
    描述
    我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?
    输入
    输入一个整数m(0<m<=5000)
    输出
    输出m的阶乘,并在输出结束之后输入一个换行符
    样例输入
    50
    样例输出
    30414093201713378043612608166064768844377641568960512000000000000
    
    程序代码:
         
     1 #include<stdio.h>
     2 #include<math.h>
     3 int main(){
     4     int n;
     5     while(scanf("%d",&n)!=EOF){
     6             long a[10000];
     7             int i,j,l,c,m=0,w;
     8             a[0]=1;
     9             for(i=1;i<=n;i++){
    10                 c=0;
    11                 for(j=0;j<=m;j++){
    12                     a[j]=a[j]*i+c;
    13                     c=a[j]/10000;
    14                     a[j]=a[j]%10000;
    15                 }
    16                 if(c>0) {m++;a[m]=c;}
    17             }
    18 
    19         w=m*4+log10(a[m])+1;
    20         printf("%ld",a[m]);
    21         for(i=m-1;i>=0;i--) printf("%4.4ld",a[i]);
    22         printf("
    ");
    23     }
    24     return 0;
    25 }
    大数阶乘位数的计算方法是(int)log10(x)+1 
    这个是计算x的位数的
    log10(n!)=log10(1)+log10(2)+log10(3)+...+log10(n)
  • 相关阅读:
    验证码缓存问题完美解决方案
    最近项目是跟框架有关的两个问题
    未与信任 SQL Server 连接相关联
    Get请求
    Post请求
    jQuery操作元素
    Dom对象和jQuery包装集
    XMLHttpRequest对象
    jQuery事件与事件对象
    处理数据集
  • 原文地址:https://www.cnblogs.com/HRuinger/p/3739285.html
Copyright © 2011-2022 走看看