http://acm.hdu.edu.cn/showproblem.php?pid=1042

题意清晰..简单明了开门见山的大数乘法..

10000的阶乘有35000多位 数组有36000够了

# include <stdio.h>
# include <string.h>
# define MAX 36000 int BigNum[MAX], NowLen; void Multi(int number)
{
int Temp[MAX]={0}, Tlen = 0, t;//Temp保存乘后结果 while(number > 0)
{
t = number % 10;//依次取当前乘数的低位
number /= 10; for(int i = 0, j = Tlen; i <= NowLen; i++)//模拟乘法 先不管进位
{
Temp[j++] += BigNum[i] * t;
}
Tlen++;//每乘完一位 Temp的开始读入位置+1
} for(int i = 0; i < MAX; i++)//处理进位 接收结果
{
if(Temp[i] > 9)
{
Temp[i + 1] += Temp[i] / 10;
BigNum[i] = Temp[i] % 10;
}
else BigNum[i] = Temp[i];
}
for(int i = MAX - 1; i >= 0; i--)//获取长度
{
if(BigNum[i] > 0)
{
NowLen = i;
break;
}
}
} int main()
{
int n;
while(scanf("%d",&n) != EOF)
{
memset(BigNum, 0, sizeof(BigNum));
BigNum[0] = 1, NowLen = 0;//初值 初始长度
for(int i = 2; i <= n; i++)//模拟乘法
Multi(i); for(int i = NowLen; i >= 0; i--)//格式输出
printf("%d",BigNum[i]);
printf("\n");
} return 0;
}

  

HDOJ-1042 N!(大数乘法)的更多相关文章

  1. HDOJ 1042 N! -- 大数运算

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1042 Problem Description Given an integer N(0 ≤ N ≤ 1 ...

  2. 51nod 1027大数乘法

    题目链接:51nod 1027大数乘法 直接模板了. #include<cstdio> #include<cstring> using namespace std; ; ; ; ...

  3. [POJ] #1001# Exponentiation : 大数乘法

    一. 题目 Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 156373   Accepted: ...

  4. 用分治法实现大数乘法,加法,减法(java实现)

    大数乘法即多项式乘法问题,求A(x)与B(x)的乘积C(x),朴素解法的复杂度O(n^2),基本思想是把多项式A(x)与B(x)写成 A(x)=a*x^m+b B(x)=c*x^m+d 其中a,b,c ...

  5. 51 Nod 1027 大数乘法【Java大数乱搞】

    1027 大数乘法 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A,B的长度  ...

  6. 51 Nod 1028 大数乘法 V2【Java大数乱搞】

    1028 大数乘法 V2 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A ...

  7. hdu_1042(模拟大数乘法)

    计算n! #include<cstring> #include<cstdio> using namespace std; ]; int main() { int n; whil ...

  8. (母函数 Catalan数 大数乘法 大数除法) Train Problem II hdu1023

    Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. 大数乘法|2012年蓝桥杯B组题解析第六题-fishers

    (9')大数乘法 对于32位字长的机器,大约超过20亿,用int类型就无法表示了,我们可以选择int64类型,但无论怎样扩展,固定的整数类型总是有表达的极限!如果对超级大整数进行精确运算呢?一个简单的 ...

随机推荐

  1. logstash 处理tomcat日志

    [root@dr-mysql01 tomcat]# cat logstash_tomcat.conf input { file { type => "zj_api" path ...

  2. setTimeout()使用

    Basic setTimeout() Example setTimeout(function() {       // Do something after 5 seconds }, ); Tip:  ...

  3. 用于下载AD官网登录账号:User name: fuxin918@fuxin918.com Passeword: s6c0W1w8

    用于下载AD官网登录账号:User name: fuxin918@fuxin918.com Passeword:  s6c0W1w8

  4. IOS 调用系统发邮件Api

    // 判断设备是否有发送邮件功能 NSString *deviceType = [UIDevice currentDevice].model; if([deviceType isEqualToStri ...

  5. java中return和continue区别

    编程语言大多是想通的,当然java也不例外,下面的在其他编程语言也是相同的道理. return与continue的区别 先看代码哦 class demo2 { public static void m ...

  6. First Bad Version

    You are a product manager and currently leading a team to develop a new product. Unfortunately, the ...

  7. BeanUtils 以及BeanUtils.populate使用

    Apache Jakarta Commons项目非常有用.我曾在许多不同的项目上或直接或间接地使用各种流行的commons组件.其中的一个强大的组件就是BeanUtils.我将说明如何使用BeanUt ...

  8. zoj 1200 Mining

    这道题被划到了动态规划里面去了,结果就是一道模拟题,懒了一点,直接用stl的优先队列,重载了一下运算符,写的时候保证只能一个在采,因为如果需要的采的次数比可以生产的次数少,那么生产的次数等于需要采的次 ...

  9. S - 骨牌铺方格(第二季水)

    Description          在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数.         例如n=3时,为2× 3方格,骨牌的铺放方案有三种, ...

  10. android ellipsize 属性详解

    TextView中内容过长时添加省略号的属性,即ellipsize 用法如下: 在XML文件中设置: android:ellipsize = "end" //省略号在结尾 andr ...