HDU 1042 N!

N!

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 83996    Accepted Submission(s): 24766

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(极光炫影)

Recommend

We have carefully selected several similar problems for you:  1715 1047 1063 1753 1316

分析:一开始以为要用高精度,然后看了下 其他人的做法,原来可以直接用数组储存当前位

然后又因为不知道 0!=1  WA了很多发..

注意,一开始数组需要多长的话,可能需要试探性的取吧,再看ans[MAXN]是否为0

代码如下:

#include <cstdio>
#include <iostream>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
const int MAXN=40000;
int ans[MAXN];
int flag;
int main()
{
    int n,r,tmp;
while(scanf("%d",&n)!=EOF){
    flag=0;
     memset(ans,0,sizeof(ans));
     ans[0]=1;
     for(int i=2;i<=n;i++)
     {
         r=0;
        for(int j=0;j<=MAXN;j++)
        {
            tmp=ans[j]*i+r;
            ans[j]=tmp%10;
            r=tmp/10;

        }
     }
       for(int i=MAXN;i>=0;i--)
       {
          if(flag==0&&ans[i]==0)
          continue;
          else
          {
              flag=1;
              printf("%d",ans[i]);
          }
       }
       printf("\n");
    }
    return 0;
}
时间: 2024-08-26 08:58:01

HDU 1042 N!的相关文章

hdu 1042 N!(大数阶乘,转化为100000这样的比较大的进制)

N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 54172    Accepted Submission(s): 15365 Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in one

HDU 1042 大数阶乘

B - 2 Time Limit:5000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1042 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. Outpu

HDU 1042 N! 参考代码

请问DIY题目做不来的队员:听进去了吗?去消化吸收了吗?能百度一下吗? 请问集训队员:有兴趣吗?有团队合作精神吗?有责任感吗?能坚持吗?能自主学习吗?能承受挫败吗? HDU 1042 N! 题意:Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! (题目链接) #include <iostream> using namespace std; //每个数组元素存放5位数 const int MAX=1000000; //

HDU 1042 N!

题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1042Problem DescriptionGiven an integer N(0 ≤ N ≤ 10000), your task is to calculate N! InputOne N in one line, process to the end of file. OutputFor each N, output N! in one line. Sample Input123 Sample

HDU 1042 N! (大数阶乘,还是Java大法好,C也不能错过!!!)

N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 73270    Accepted Submission(s): 21210 Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in o

HDU - 1042 - N! - JAVA

http://acm.hdu.edu.cn/showproblem.php?pid=1042 大数嘛,直接用JAVA. 为什么要开64路?好像我觉得会快一点--其实并没有快-- import java.io.*; import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while

hdu 1042

高精度大数运算其实就是由于数字过大必须要用数组来存数据 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1020 #include<stdio.h> #include<math.h> #include<iterator> #include<iostream> #include<algorithm> #include<set> using namespace std; int main()

HDU 1042 大数计算

这道题一开始就采用将一万个解的表打好的话,虽然时间效率比较高,但是内存占用太大,就MLE 这里写好大数后,每次输入一个n,然后再老老实实一个个求阶层就好 java代码: 1 /** 2 * @(#)Main.java 3 * 4 * 5 * @author 6 * @version 1.00 2014/12/21 7 */ 8 import java.util.*; 9 import java.math.*; 10 11 public class Main { 12 //public stati

HDU 1042 N! 高精度乘法

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 题目意思很简单,就是让你求N的阶乘,但是N的范围有10000,所