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 <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string.h>
using namespace std;
const int maxn=;
int d[maxn];
int main()
{
int n;
while(cin>>n){
memset(d,,sizeof(d));
d[]=;
int t=,tmp=,carry=;
for(int i=;i<=n;i++){
for(int j=;j<=t;j++){
tmp=d[j]*i+carry;
d[j]=tmp%;
carry=tmp/;
}
while(carry!=){
d[++t]=carry%;
carry/=;
}
}
for(int i=t;i>=;i--){
cout<<d[i];
}
cout<<endl;
}
return ;
}

Hdu1042 N! (阶乘高精度模板)的更多相关文章

  1. bzoj 3907 网格 bzoj2822 [AHOI2012]树屋阶梯——卡特兰数(阶乘高精度模板)

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3907 https://www.lydsy.com/JudgeOnline/problem.p ...

  2. 高精度模板 支持各种运算 c++

    绪言 自从有了高精度模板,妈妈再也不用怕我不会打高精度了! 代码 代码长度与日俱增啊~~~ #include<iostream> #include<cstring> #incl ...

  3. [Template]高精度模板

    重新写一下高精度模板(不要问我为什么) 自认为代码风格比较漂亮(雾 如果有更好的写法欢迎赐教 封装结构体big B是压位用的进制,W是每位长度 size表示长度,d[]就是保存的数字,倒着保存,从1开 ...

  4. C++高精度模板

    原文地址:http://blog.csdn.net/wall_f/article/details/8373395 原文只附代码,没有解析,本文增加了一些对代码的解释. 请注意:本模板不涉及实数运算与负 ...

  5. [note]高精度模板

    高精度模板 先定义一个struct struct gj{ int l,s[N]; bool fh; void Print(){ if(fh)putchar('-'); for(int i=l;i> ...

  6. Java 大数、高精度模板

    介绍: java中用于操作大数的类主要有两个,一个是BigInteger,代表大整数类用于对大整数进行操作,另一个是BigDecimal,代表高精度类,用于对比较大或精度比较高的浮点型数据进行操作.因 ...

  7. JAVA高精度模板

    刚开始还坚持用C++写高精来着,后来发现JAVA写高精方便太多了,所以也来学习一下JAVA高精度的模板. 参考:https://www.cnblogs.com/imzscilovecode/p/883 ...

  8. 高精度模板 Luogu P1932 A+B & A-B & A*B & A/B Problem

    P1932 A+B & A-B & A*B & A/B Problem 题目背景 这个题目很新颖吧!!! 题目描述 求A.B的和差积商余! 输入输出格式 输入格式: 两个数两行 ...

  9. 大整数类BIGN的设计与实现 C++高精度模板

    首先感谢刘汝佳所著的<算法竞赛入门经典>. 众所周知,C++中储存能力最大的unsigned long long 也是有着一个上限,如果我们想计算非常大的整数时,就不知所措了,所以,我写了 ...

随机推荐

  1. Thread Based Parallelism - Thread Synchronization With a Condition

    Thread Based Parallelism - Thread Synchronization With a Condition from threading import Thread, Con ...

  2. Mysql 升级重装后连接出错 Table \'performance_schema.session_variables\' doesn\'t exist

    升级重装后  连接出错 报这个错误 Table 'performance_schema.session_variables' doesn't exist   使用这个命令即可 [root@localh ...

  3. OpenLayers 6 学习笔记2 WMS服务避坑记录

    心血来潮,花1小时安装软件写代码+复习api,顺便熟悉一波wms 再次强化认知了wms获取要素的能力没有wfs强,有待考究 原文链接(转载请声明@秋意正寒  博客园/知乎/B站/csdn/小专栏):h ...

  4. rpm | 升级软件包

    rpm | 升级软件包 检查已安装包 rpm -qa | grep samba samba-common-3.6.9-164.el6.x86_64 samba-3.6.9-164.el6.x86_64 ...

  5. 【idea激活码】,【WebStorm激活码】,【DataGrip激活码】,【IntelliJ 全家桶系列】,【定期更新】,【第一期】

    IntelliJ IDEA.PyCharm.PhpStorm.WebStorm.RubyMide.AppCode.CLion.GoLand.DataGrip.Rider.Android Studio可 ...

  6. Kubernetes label简单使用

    # 查看集群中的node节点 # kubectl get nodes NAME STATUS ROLES AGE VERSION server01 Ready <none> 130d v1 ...

  7. Mac Docker Desktop "Mounts denied: EOF."解决方法

    环境 系统: Mac OS Catalina Docker Desktop: 问题描述 在Mac环境下创建容器时用"-v"参数挂载目录出现"docker: Error r ...

  8. .NET CORE(C#) WPF 值得推荐的动画菜单设计

    微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. .NET CORE(C#) WPF 值得推荐的动画菜单设计 阅读导航 本文背景 代码实现 本文 ...

  9. Windows2008R2 一键安全优化脚本

      ::author vim ::QQ 82996821 ::filename Windows2008R2_safe_auto_set.bat   :start @echo off color 0a ...

  10. SQL中的real、float、decimal、numeric数据类型区别

    概述: 浮点数据类型包括real型.float型.decimal型和numeric型.浮点数据类型用于存储十进制小数. 在SQL Server 中浮点数值的数据采用上舍入(Round up)的方式进行 ...