N!

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

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
 
思路分析:简单的高精度算法。
  1.基本思想:
  把运算结果倒着保存在一个大数组f中。
  每次循环更新每一位*(当前的操作数i)+进位c.并处理超过当前数字长度的进位c。更新数字长度。
  最后,找到不为零的数组位置,开始倒着输出即可。
 #include<cstdlib>
#include<cstdio>
#include<string.h>
#define MAX 10000
int f[MAX];
int main()
{
int n;//阶乘数
while (scanf("%d",&n)!=EOF)
{
memset(f,,sizeof(f));//清空运算数组
f[]=;
int i,j,count=;//数的总位数,进位时+1
for (i = ; i <=n; i++)//<=n的数循环高精度
{
int c=;//进位
for (j = ; j < count; j++)
{
int ans=f[j]*i+c;
f[j]=ans%;//所在位取余数
c=ans/;
}
while (c)//进位
{
f[count++]=c%;
c/=;
}
}
int k=MAX-;
while (!f[k])k--;//找到数组结果不为零的开始.
for (i = k; i >= ; i--)
printf("%d",f[i]);
printf("\n");
}
return ;
}

HDU 1042 N!(高精度计算阶乘)的更多相关文章

  1. HDU 1042 大数阶乘

    B - 2 Time Limit:5000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  2. HDU 1042 N! 參考代码

    HDU 1042 N! 题意:给定整数N(0 ≤ N ≤ 10000), 求 N! (题目链接) #include <iostream> using namespace std; //每一 ...

  3. HDU 1042 N!(高精度阶乘、大数乘法)

    N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submi ...

  4. hdu 1042 N!(大数的阶乘)

    N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  5. hdu 1042 N!

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1042 N! Description Given an integer N(0 ≤ N ≤ 10000) ...

  6. hdu 1042 N!(高精度乘法 + 缩进)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 题目大意:求n!, n 的上限是10000. 解题思路:高精度乘法 , 因为数据量比较大, 所以 ...

  7. Hdu 1042 N! (高精度数)

    Problem Description Givenan integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input OneN in one ...

  8. HDU 1042 N!(高精度乘)

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

  9. hdu 1042 N!(大数)

    题意:求n!(0 ≤ N ≤ 10000) 思路:大数,用数组存储 1.首先要考虑数据N!的位数,因为最大是10000!,可以计算一下大概是5+9000*4+900*3+90*2+10*1=38865 ...

随机推荐

  1. MSSql ID自动增长删除数据重1开始

    dbcc checkident('db_Tome1.dbo.员工信息表',reseed,0) 注:dbcc checkident('表名',reseed,0)

  2. DB天气app冲刺第五天

    今天上了软工的一节课,感觉自己前几天的方向错了,而且基本是在耗时间,因为虽然一直在努力的看书 编代码,但效果不明显.所以今天要好好想一个新的方向重新来过. 明天送上计划.

  3. ios7 sdk 新特性

    iOS 7 is a major update with compelling features for developers to incorporate into their apps. The ...

  4. shell 流程控制

    for循环: #!/bin/bash for file in $(ls /ect) do echo $file done

  5. 应该知道的25个非常有用的CSS技巧

    在我们的前端CSS编码当中,经常要设置特殊的字体效果,边框圆角等等,还要考虑兼 容性的问题, CSS网页布局,说难,其实很简单.说它容易,往往有很多问题困扰着新 手,在中介绍了非常多的技巧,这些小技巧 ...

  6. Es索引优化

    https://www.elastic.co/guide/en/elasticsearch/guide/current/hardware.html https://www.elastic.co/gui ...

  7. MongoDB实战指南(五):MongoDB中的聚集分析

    聚集操作是对数据进行分析的有效手段.MongoDB主要提供了三种对数据进行分析计算的方式:管道模式聚集分析,MapReduce聚集分析,简单函数和命令的聚集分析. 1. 管道模式进行聚集 这里所说的管 ...

  8. vcastr2.0插件超级简单使用

                Vcastr2.0简单使用 友情提示:1.蓝色文字为必修改内容.2.#字符后面是解释该代码段的主要内容 1. 引用swfobject.js文件 #public/videoplu ...

  9. ANDROID_MARS学习笔记_S02_011_ANIMATION_LayoutAnimationController

    一.简介 二.代码1.xml(1)activity_main.xml <ListView android:id="@id/android:list" android:layo ...

  10. 浏览器助手,请求拦截,后台模拟键鼠操作,页内嵌入JS

    http://www.cnblogs.com/ /// <summary>        /// 网页浏览器助手        /// 请求拦截,后台模拟键鼠操作,页内嵌入JS       ...