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. Jetty使用

    目标:在Linux以及Windows下面配置应用: 之前使用过smartfox,安装的时候弹出一个浏览器,一路next,印象很深刻.只是记得他是使用Jetty.最近做的项目也是需要进行配置:过往都是使 ...

  2. UIScrollView解决touchesBegan等方法不能触发的解方案

    新建一个类继承自UIScrollView  并重写下面的方法 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [su ...

  3. python 读写文本文件

    本人最近新学python ,用到文本文件的读取,经过一番研究,从网上查找资料,经过测试,总结了一下读取文本文件的方法. 1.在读取文本文件的时无非有两种方法: a.f=open('filename', ...

  4. zoj 3761

    很简单但很虐心的一道题: 我感觉自己的算法没错,但是老是过不了:= = 但是还是把代码贴出来: 我的方法,用并查集的方式做一课树,然后对树进行遍历: 有多少棵树就有多少个点剩余: #include&l ...

  5. "Money, Money, Money"

    acdream1408:http://115.28.76.232/problem?pid=1408 题意:给你一个x,让你构造a,b,是的na+bm可以组成大于x的所有的数.a>1,b>1 ...

  6. dropdownlist无刷新传值

    既然局部刷新,其实没有必要用服务器控件,即便用了服务器控件,也不应该将AutoPostBack="true" ,这将导致页面回发并刷新,因此去掉下拉框的该属性 至于局部改变div的 ...

  7. Android USB Host 与 Hid 设备通信bulkTransfer()返回-1问题的原因

    近期一直在做Android USB Host 与USB Hid设备(STM32FXXX)的通信,遇到了很多问题.项目源码以及所遇到的其他问题可以见本博客其他相关文章,这里重点讲一下bulkTransf ...

  8. jquery ajax传递数组给php

    写成:var data = {'item[]':item}; $.post(url,data,function(return_data) 写成item:item会导致数据缺失. 更多:http://w ...

  9. Drawable(2)State list Drawable Resource介绍

    State List A StateListDrawable is a drawable object defined in XML that uses a several different ima ...

  10. 【HDOJ】1033 Edge

    题目英文太多,简单翻译了一下:1. For products that are wrapped in small packings it is necessary that the sheet of ...