zoukankan      html  css  js  c++  java
  • ACM HDU 1042 N!(高精度计算阶乘)

    N!

    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 24579    Accepted Submission(s): 6774


    Problem Description
    Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
     

    Input
    One N in one line, process to the end of file.
     

    Output
    For each N, output N! in one line.
     

    Sample Input
    1 2 3
     

    Sample Output
    1 2 6
     

    Author
    JGShining(极光炫影)
     
     
    #include<stdio.h>
    #include
    <string.h>
    const int MAXN=40000;//如果是10000的阶乘,改为40000就够了
    int f[MAXN];
    int main()
    {
    int i,j,n;
    while(scanf("%d",&n)!=EOF)
    {
    memset(f,
    0,sizeof(f));
    f[
    0]=1;
    for(i=2;i<=n;i++)
    {
    int c=0;
    for(j=0;j<MAXN;j++)
    {
    int s=f[j]*i+c;
    f[j]
    =s%10;
    c
    =s/10;
    }
    }
    for(j=MAXN-1;j>=0;j--)
    if(f[j]) break;//忽略前导0
    for(i=j;i>=0;i--) printf("%d",f[i]);
    printf(
    "\n");
    }
    return 0;
    }

  • 相关阅读:
    验证码处理函数
    Apache2.2下载及安装
    centos6.4、6.5、7.0环境下载及安装
    数据库实务 实务隔离级别
    InnoDB 锁
    索引常见问题处理
    数据库索引 B-Tree索引 hash索引
    JVM学习-(2)
    jvm学习-(1)
    linux杂记
  • 原文地址:https://www.cnblogs.com/kuangbin/p/2172795.html
Copyright © 2011-2022 走看看