HDOJ 1042 N! -- 大数运算
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1042
1
2
3
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! -- 大数运算的更多相关文章
- 大数运算(python2)
偶然又遇到了一道大数题,据说python大数运算好屌,试了一发,果然方便-1 a = int( raw_input() ); //注意这里是按行读入的,即每行只读一个数 b = int( raw_in ...
- 收藏的一段关于java大数运算的代码
收藏的一段关于java大数运算的代码: package study_02.number; import java.math.BigDecimal; import java.math.BigIntege ...
- [PKU2389]Bull Math (大数运算)
Description Bulls are so much better at math than the cows. They can multiply huge integers together ...
- java 大数运算[转]
用JAVA 实现算术表达式(1234324234324 + 8938459043545)/5 + 343434343432.59845 因为JAVA语言中的long 定义的变量值的最大数受到限制,例如 ...
- A+B大数运算
基础加法大数运算: [https://vjudge.net/problem/HDU-1002] 题目: 输入两个长度不超过1000的整数求出sum. 思路: 由于数字很大不能直接加,用字符串形式输入, ...
- HOJ 2148&POJ 2680(DP递推,加大数运算)
Computer Transformation Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4561 Accepted: 17 ...
- 九度OJ 1051:数字阶梯求和 (大数运算)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6718 解决:2280 题目描述: 给定a和n,计算a+aa+aaa+a...a(n个a)的和. 输入: 测试数据有多组,输入a,n(1&l ...
- 九度OJ 1119:Integer Inquiry(整数相加) (大数运算)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:679 解决:357 题目描述: One of the first users of BIT's new supercomputer was ...
- lua实现大数运算
lua实现的大数运算,代码超短,眼下仅仅实现的加减乘运算 ------------------------------------------------ --name: bigInt --creat ...
随机推荐
- Swif基本语法以及与OC比较三
(未 经 博 主 同 意,不 得 转 载 !) ------------------------华丽分割线----------------------- // // main.swift ...
- maven快速入门
一.maven maven可以说是管理项目的优秀工具,管理jar包 二.mave安装 1.先安装jdk(本文不详细讲) 2.安装maven ①.maven下载 http://maven.apach ...
- dataGridView控件--未将对象引用设置添加到对象的实例
上篇博客中我完成了如何将控件中的数据导出到excel中dataGridView控件--导出Excel,当我成功导出后,又再次遇到了新问题---未将对象引用设置添加到对象的实例 解决办法: 1 .将代 ...
- EF中Database.SqlQuery
本文转载:http://www.cnblogs.com/daimage/archive/2012/07/04/2575844.html EF中Database.SqlQuery<TElement ...
- 使用JDK自带jvisualvm监控tomcat
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- JS保留两位小数 四舍五入函数
js 四舍五入函数 toFixed(),里面的参数 就是保留小数的位数. <script language="javascript"> document.write(& ...
- select poll使用
select poll使用 2.1. 怎样管理多个连接?“我想同一时候监控一个以上的文件描写叙述符(fd)/连接(connection)/流(stream),应该怎么办?” 使用 select ...
- 定时自动同步文件,支持多文件夹同步,支持过滤文件和文件夹,解决FileSystemWatcher多次文件触发事件(源码)
博客园里面有很多同步工具和软件,关于FileSystemWatcher类解释的也很多,但收集了很多文章后,感觉没好的方法,自己没事写了一个定时文件同步,借鉴了很多博客园朋友的东西: 上主菜: 配置文件 ...
- select option jquery javascript
jQuery获取Select选择的Text和Value: $('#myselect').find('option:selected').attr('ent_id'); $('#ent_id' ...
- mvc ajax_返回数据
假设cshtml文件中是这样的: <script type="text/javascript"> $(document).ready(function(){ $(&qu ...