题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1042

Problem Description
Given an integer N( ≤ N ≤ ), 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 Sample Output

题意:求N!(N<10000)

方法:用数组储存数,因为位数太多,每位存5个数

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
#define N 10010
#define met(a,b) memset(a,b,sizeof(a));
vector<vector<int> >Q;
int a[N],n;
void add(int m)
{
for(int i=;i<N;i++)
{
a[i]=a[i]*m;
}
for(int i=;i<N-;i++)
{
a[i+]+=a[i]/;
a[i]=a[i]%;
}
}
void put(int a[])
{
int i=N-;
while(!a[i])i--;
printf("%d",a[i]);
for(i--;i>=;i--)
printf("%04d",a[i]);
puts("");
}
void init()
{
a[]=;
for(int i=;i<=n;i++)
{
add(i);
}
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
if(n==)
{
printf("1\n");
continue;
} met(a,);
init();
put(a);
}
return ;
}

(hdu)1042 N! 大数相乘的更多相关文章

  1. HDU 1042 大数阶乘

    B - 2 Time Limit:5000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  2. POJ 2389 Bull Math(水~Java -大数相乘)

    题目链接:http://poj.org/problem?id=2389 题目大意: 大数相乘. 解题思路: java BigInteger类解决 o.0 AC Code: import java.ma ...

  3. 大数相乘算法C++版

    #include <iostream> #include <cstring> using namespace std; #define null 0 #define MAXN ...

  4. java版大数相乘

    在搞ACM的时候遇到大数相乘的问题,在网上找了一下,看到了一个c++版本的 http://blog.csdn.net/jianzhibeihang/article/details/4948267 用j ...

  5. Linux C/C++ 编程练手 --- 大数相加和大数相乘

    最近写了一个大数相乘和相加的程序,结果看起来是对的.不过期间的效率可能不是最好的,有些地方也是临时为了解决问题而直接写出来的. 可以大概说一下相乘和相加的解决思路(当然,大数操作基本就是两个字符串的操 ...

  6. HDU 1042 N! 參考代码

    HDU 1042 N! 题意:给定整数N(0 ≤ N ≤ 10000), 求 N! (题目链接) #include <iostream> using namespace std; //每一 ...

  7. Karatsuba乘法--实现大数相乘

    Karatsuba乘法 Karatsuba乘法是一种快速乘法.此算法在1960年由Anatolii Alexeevitch Karatsuba 提出,并于1962年得以发表.此算法主要用于两个大数相乘 ...

  8. leetcode 43 Multiply Strings 大数相乘

    感觉是大数相乘算法里面最能够描述.模拟演算过程的思路 class Solution { public String multiply(String num1, String num2) { if(nu ...

  9. Java 大数相乘、大数相加、大数相减

    思路来源:: https://blog.csdn.net/lichong_87/article/details/6860329 /** * @date 2018/6/22 * @description ...

随机推荐

  1. RIA算法解决最小覆盖圆问题

    一.概念引入         最小包围圆问题:对于给定的平面上甩个点所组成的一个集合P,求出P的最小包围圆,即包含P中所有点.半径最小的那个圆.也就是求出这个最小 包围圆的圆心位置和半径.       ...

  2. Installing your app on your Windows RT device

    Alright… so my app is almost finished and I want to install it for real on my Surface tablet. How do ...

  3. Redis_php 学习

    转载内容: PhpRedis是php的一个扩展,效率是相当高有链表排序功能,对创建内存级的模块业务关系很有用;以下是redis官方提供的命令使用技巧: Redis::__construct构造函数 1 ...

  4. 教程-Delphi各种退出break,continue, exit,abort, halt, runerror

    delphi中表示跳出的有break,continue, exit,abort, halt, runerror.1.break 强制退出循环(只能放在循环中),用于从For语句,while语句或rep ...

  5. poj 3469 Dual Core CPU【求最小割容量】

    Dual Core CPU Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 21453   Accepted: 9297 ...

  6. Prime Land

    http://poj.org/problem?id=1365 题意:给定一个数字n的拆分形式,然后让你求解n-1的值: 解析:直接爆搞 // File Name: poj1365.cpp // Aut ...

  7. [struts2]struts标签遍历map[转]

    转至:http://hanxin0311.iteye.com/blog/1745792 private Map<String, String> strMap = new HashMap&l ...

  8. Java条形码生成方案及二维码要点

    1.什么是条形码及其应用 条形码(barcode)是将宽度不等的多个黑条和空白,按照一定的规则排列,用来表示一组信息的图形标识符.常见的条形码是由反射率相差很大的黑条和白条排成的平行线图案. 条形码可 ...

  9. ubuntu14.04如何卸载qq

    ubuntu安装了wine qq怎么去卸载呢?现在wine qq 比较好用的有ubuntukylin官网与deepin linux官网使用的deepin版本wine qq 2012国际版,还有Long ...

  10. Linux系统及应用问题分析排查工具

    linux 阿里技术协会 摘要: Linux服务器上经常遇到一些系统和应用上的问题,如何分析排查,需要利器,下面总结列表了一些常用工具.trace tool:最后也列举了最近hadoop社区在开发发展 ...