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;
    }

  • 相关阅读:
    clion打断点不生效
    PHP加密解密
    细说MySQL表操作
    细说MySQL数据库操作
    终端(命令行)连接MySQL
    MySQL结构
    求1!+(1!+3!)+(1!+3!+5!)+...+(1!+3!+5!+7!+9!)的值
    react 生命周期
    React TS 组件 Demo
    react-redux 实现原理
  • 原文地址:https://www.cnblogs.com/kuangbin/p/2172795.html
Copyright © 2011-2022 走看看