题目地址: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. 简单的谈一下.NET下的AOP

    AOP有着它优良的好处, 从一个层面上去关心一个问题, .NET对此有良好的支持.如果硬生生的看MSDN不理解里面的思想是有掉入深渊的感觉的. 为了理解AOP的机制, 我们从需求开始说起,实现AOP就 ...

  2. 详解UML中的聚合,关联,泛化等关系

    1. Overview UML设计类中,类的关系分为Generalization(泛化),Dependency(依赖关系).Association(关联关系).Aggregation(聚合关系).Co ...

  3. 逻辑网络(Logical Network)

    Introduction The VMM documentation indicates that “A logical network is used to organize and simplif ...

  4. windows 2003 远程登录时如何修改管理员密码

    今天买的vps,需要修改密码.但是自己不会,看网上好多人都说是,按ctrl+alt+del .但是我试过之后发现不对,后来又找到说是使用ctrl+alt+end  更改密码就可以了. 千万不要通过那个 ...

  5. ThinkPHP3.2.3新特性之:数据库设置

    ThinkPHP3.2.3版本数据库驱动采用PDO完全重写,配置和使用上面也比之前版本更加灵活和强大,我们来了解下如何使用. 首先,3.2.3的数据库配置信息有所调整,完整的数据库设置包括: /* 数 ...

  6. Android 文件读写的例子

    import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStrea ...

  7. innobackupex --slave-info参数的含义和适用场景

    http://blog.itpub.net/28916011/viewspace-1969135/       我有个问题一直没弄明白,就是innobackupex里面的--slave-info这个参 ...

  8. Debug Certificate expired on 11-5-8 上午 6:26

    好久没用电脑上的eclipse,今天新建了个安卓项目,发现报下面的错误:   后来得知: 是Debug证书过期所致. android应用必须经过签名证书进行数字签名后,才能安装,在开发调试阶段,默认情 ...

  9. C#_Ajax分页MVCPager

    UCJqOrderList @model PagedList<Order> <div id="dvOrders"> <table width=&quo ...

  10. mysql聚合函数

    1.统计一下插入的数据总数 SELECT COUNT(giftCertificateId) AS number FROM gift_certificate WHERE giftCertificateN ...