题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1042

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

#include <stdio.h>
#include <string.h> /* 一个数组元素表示 4 个十进制位,即数组是万进制的 */
#define BIG_RADIX 10000
#define RADIX_LEN 4
/* 10000! 有 35660 位 */
#define MAX_LEN (35660/RADIX_LEN + 1) int x[MAX_LEN + 1]; void Big_Print(){
int i;
int start_output = 0;//用于跳过多余的0 for (i = MAX_LEN; i >= 0; --i){
if (start_output == 1){//如果多余的0已经跳过,则输出
printf("%04d", x[i]);
}
else if (x[i] > 0){//表示多余的0已经跳过
printf("%d", x[i]);
start_output = 1;
}
}
if (start_output == 0)//如果全为0
printf("0");
} void Big_Multiple(int y){
int i;
int carry = 0;//保存进位
int tmp; for (i = 0; i < MAX_LEN; ++i){
tmp = x[i] * y + carry;
x[i] = tmp % BIG_RADIX;
carry = tmp / BIG_RADIX;
}
} void Big_Factorial(int N){
int i; memset(x, 0, sizeof(x));
x[0] = 1;
for (i = 2; i <= N; ++i){
Big_Multiple(i);
}
} int main(void){
int N; while (scanf("%d", &N) != EOF){
Big_Factorial(N);
Big_Print();
printf("\n");
}
}

HDOJ 1042 N! -- 大数运算的更多相关文章

  1. 大数运算(python2)

    偶然又遇到了一道大数题,据说python大数运算好屌,试了一发,果然方便-1 a = int( raw_input() ); //注意这里是按行读入的,即每行只读一个数 b = int( raw_in ...

  2. 收藏的一段关于java大数运算的代码

    收藏的一段关于java大数运算的代码: package study_02.number; import java.math.BigDecimal; import java.math.BigIntege ...

  3. [PKU2389]Bull Math (大数运算)

    Description Bulls are so much better at math than the cows. They can multiply huge integers together ...

  4. java 大数运算[转]

    用JAVA 实现算术表达式(1234324234324 + 8938459043545)/5 + 343434343432.59845 因为JAVA语言中的long 定义的变量值的最大数受到限制,例如 ...

  5. A+B大数运算

    基础加法大数运算: [https://vjudge.net/problem/HDU-1002] 题目: 输入两个长度不超过1000的整数求出sum. 思路: 由于数字很大不能直接加,用字符串形式输入, ...

  6. HOJ 2148&POJ 2680(DP递推,加大数运算)

    Computer Transformation Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4561 Accepted: 17 ...

  7. 九度OJ 1051:数字阶梯求和 (大数运算)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6718 解决:2280 题目描述: 给定a和n,计算a+aa+aaa+a...a(n个a)的和. 输入: 测试数据有多组,输入a,n(1&l ...

  8. 九度OJ 1119:Integer Inquiry(整数相加) (大数运算)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:679 解决:357 题目描述: One of the first users of BIT's new supercomputer was ...

  9. lua实现大数运算

    lua实现的大数运算,代码超短,眼下仅仅实现的加减乘运算 ------------------------------------------------ --name: bigInt --creat ...

随机推荐

  1. SQLite使用教程4 创建数据库

    http://www.runoob.com/sqlite/sqlite-create-database.html SQLite 创建数据库 SQLite 的 sqlite3 命令被用来创建新的 SQL ...

  2. <property name="current_session_context_class">thread</property> 属性

    <property name="current_session_context_class">thread</property>这个属性的作用:这样配置是本 ...

  3. Unity3d 使用NPOI读写Excel 遇到的问题

    开发环境:unity5.3  NPOI(.net 2.0版  http://npoi.codeplex.com/) 运行环境:PC版, 其他平台没有测试 先上效果图: 实现步骤: 1.新建一个Exce ...

  4. XMPP——Smack[1]连接、登陆及账户操作

    临毕业前,应需求,花了三天写了个小的聊天工具,貌似简陋得很….若有机会再完善吧,目前毕业季,处理毕业事宜,还要准备即将的入职. 眼瞅着大学四年就这么结束了,哎. 开始吧,四篇博文简单介绍下基本实现,由 ...

  5. CentOS6.2下安装eclipse

    在eclipse官网下载eclipse的linux版本(此处省略下载过程),我下载的是eclipse-jee-indigo-SR2-linux-gtk.tar.gz,下面是安装过程:  1.sudo ...

  6. linux提权总结(外文)

    Before starting, I would like to point out - I'm no expert. As far as I know, there isn't a "ma ...

  7. Windows Server 2008找回密码

    1.通过Windows Server 2008 R2的安装光盘引导计算机启动,映像加载完毕后 ,按 Shift+F10 ,打开命令提示符界面,进入Windows目录所在分区(cd windows\sy ...

  8. sql函数:汉字转换为拼音

    sql数据库自定义一个函数把下面代码写进去 功能是得到汉字拼音首字母create function fun_getPY(@str nvarchar(4000)) returns nvarchar(40 ...

  9. 《高级Perl编程》 读书笔记

    http://blog.chinaunix.net/uid-20767124-id-1849881.html

  10. 快递查询API接口对接方法

    各类接口 快递查询API有即时查询和订阅查询两种,即时是请求即返回数据,订阅则是订阅快递单号到接口,有物流轨迹更新则全量返回数据.目前常用的有快递鸟.快递100.快递网等. 快递鸟即时API可以查询3 ...