题目地址: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. linux makefile: c++ 编程_基础入门_如何开始?

    学习android 终究还是需要研究一下其底层框架,所以,学习c++很有必要. 这篇博客,算是linux(ubuntu) 下学习 c++ 的一个入门. 刚开始学习编程语言的时候,最好还是使用命令行操作 ...

  2. Aizu 2450 Do use segment tree 树链剖分+线段树

    Do use segment tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.bnuoj.com/v3/problem_show ...

  3. 2015北京网络赛 H题 Fractal 找规律

    Fractal Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acmicpc2015beijingo ...

  4. android 处理网络状态——无网,2g,3g,wifi,ethernet,other

    今天在一位很牛逼的学长的博客里面看到了这段代码后,很是激动啊,于是就“偷”了过来,嘿嘿....为自己也为更多需要它的程序媛 直接上代码: public class GetNetWorkStateAct ...

  5. Graph(2014辽宁ACM省赛)

    问题 F: Graph 时间限制: 1 Sec  内存限制: 128 MB 提交: 30  解决: 5 [cid=1073&pid=5&langmask=0" style=& ...

  6. wcf自身作为宿主的一个小案例

    第一步:创建整个解决方案 service.interface:用于定义服务的契约(所有的类的接口)引用了wcf的核心程序集system.ServiceModel.dll service:用于定义服务类 ...

  7. DRM in Android

    我们Tieto公司的MM专家在<程序员>第8期上发表了一篇关于DRM的文章,请大家指教. DRM in Android DRM,英文全称为Digital Rights Management ...

  8. CentOS下yum安装mysql,jdk以及tomcat

    首先说明,服务器是阿里云的,centos6.3_64位安全加固版.首先需要登陆进来,使用的是putty,因为最初的时候,Xshell登陆会被拒绝. 0. 创建个人文件夹 # 使用 yum 安装tomc ...

  9. C# 工厂模式示例

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 工厂模式 ...

  10. SurfaceView的使用

    1.概念 SurfaceView是View类的子类,可以直接从内存或者DMA等硬件接口取得图像数据,是个非常重要的绘图视图.它的特性是:可以在主线程之外的 线程中向屏幕绘图上.这样可以避免画图任务繁重 ...