题目地址: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. C# Redis Server分布式缓存编程(二)

    在Redis编程中, 实体和集合类型则更加有趣和实用 namespace Zeus.Cache.Redis.Demo { public class Person { public int Id { g ...

  2. WordPress Import 上传的文件尺寸超过php.ini中定义的upload_max_filesize值--&gt;解决方法。

    參考一: WordPress Importer上传导入备份文件时遇到这样一个错误,提示"上传的文件尺寸超过 php.ini 中定义的 upload_max_filesize 值". ...

  3. android---APN切换

    android手机客户端在上传文件时,有时候会一直失败,其可能的原因是APN的设置.wap下的成功率极低,所以在进行文件上传时最好设置下 apn为net形式.下面是我在网上找的一些代码,是由wap转n ...

  4. sphinx中过滤的简单介绍

    1.过滤字符串为空的一些记录的话,可以在sql_query中直接加上where来限制,如: sql_query  = \  SELECT a.location_id as id,a.location_ ...

  5. C 高级编程5 IO与文件权限

    三.基于文件的描术符号 .得到文件描术符号/释入文件描术符号 a.文件类型 目录文件 d 普通文件 f 字符设务文件 c 块设备文件 b 软连接文件 l 管道文件 p socket文件 s 字符设备文 ...

  6. Linux性能优化--CPU[备忘]

    http://kumu-linux.github.io/blog/2014/04/21/performance-cpu/

  7. 在饼图上显示百分比值(报表生成器和 SSRS)

    在饼图上显示百分比值(报表生成器和 SSRS) 默认情况下,图例中显示了类别来标识每个值. 如果使用了类别标签标记饼图,则可能希望在图例中显示百分比. 注意 在 SQL Server Data Too ...

  8. Linux中的终端、控制台、tty、pty等概念

    参考:http://news.newhua.com/news1/program_language/2010/623/10623141048745773199BCF0CFH6AKB9930IGCFKHB ...

  9. php一些技术要点连接地址

    http基本认证: http://www.php.net/manual/zh/features.http-auth.php

  10. 多线程NSOperation

      NSOperation(经常使用): 1.为什么会有NSOperation?弥补gcd的一些问题:1)下载为例子:如果gcd放到队列中的block操作面对网络有问题,block之外无法取消bloc ...