题目链接: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. UVa1449 - Dominating Patterns(AC自动机)

    题目大意 给定n个由小写字母组成的字符串和一个文本串T,你的任务是找出那些字符串在文本中出现的次数最多 题解 一个文本串,多个模式串,这刚好是AC自动机处理的问题 代码: #include <i ...

  2. 委托demo

    delegate bool Filter(string s); class test { static void Main() { Filter f=new Filter(A); Display(ne ...

  3. 高并发Web服务的演变:节约系统内存和CPU

    一.越来越多的并发连接数 现在的Web系统面对的并发连接数在近几年呈现指数增长,高并发成为了一种常态,给Web系统带来不小的挑战.以最简单粗暴的方式解决,就是增加Web系统的机器和升级硬件配置.虽然现 ...

  4. 有关gcc的扩展__attribute__((unused))

    ================================ Author: taoyuetao Email: tao_yuetao@yahoo.com.cn Blog: taoyuetao.cu ...

  5. JavaScript constructors, prototypes, and the `new` keyword

    Are you baffled(阻碍:使迷惑) by the new operator in JavaScript? Wonder what the difference between a func ...

  6. ios:Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?

    - (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)laun ...

  7. (贪心5.1.1)POJ 1230 Pass-Muraille

    /* * POJ_1230.cpp * * Created on: 2013年10月9日 * Author: Administrator */ #include <iostream> #i ...

  8. 虚机分配静态IP地址

    在为虚机分配静态IP地址池的IP时,如果报错“没有从与 VMSubnet 相关的 IP 池中为虚拟网络适配器 9i [MAC: 001DD8B71C17] 分配 CA (客户地址)” 使用“动态获取” ...

  9. Android虚拟机Dalvik介绍

     Dalvik和标准Java虚拟机(JVM)之间的首要差别之一,就是Dalvik基于寄存器,而JVM基于栈.一直以来都有人在猜测,选择基于寄存器的方式是因为它对提前优化(ahead-of-time o ...

  10. 【系列】Matei Zaharia(Spark系统作者)博士论文-0 摘要

    随着处理器提升速度下降和数据量的不断增长,非常多公司和组织(既有互联网公司也有传统的企业另一些研究机构)都要求他们的应用可以Scale out到更大的分布式系统上(比方整个数据中心). 这些应用又分为 ...