大数阶乘(10000级别) 51Nod 1057
来源:互联网 发布:手机联系淘宝人工客服 编辑:程序博客网 时间:2024/06/05 01:02
题目链接:
51Nod 1057
问题描述
输入N求N的阶乘的准确值。
Input
输入N(1 <= N <= 10000)
Output
输出N的阶乘
Input示例
5
Output示例
120
思路:
一百万亿进制(14个0),大数相乘,求阶乘
代码:
#include<iostream>#include<stdio.h>#include<algorithm>#define LL long longusing namespace std;#define mod 100000000000000;//14个0const int N = 1000086;LL a[N]; int main(){ int n; scanf("%d", &n); LL l = 0; a[0] = 1; for(int i = 1; i <= n; i++) { LL c = 0; for(int j = 0; j <= l; j++) { LL t = a[j] * i + c; a[j] = t % mod; c = t / mod; } if(c != 0) { l++; a[l] = c; } } printf("%lld", a[l]); for(int i = l-1; i >= 0; i--) { printf("%014lld", a[i]);//保留前导0 } return 0;}
0 0
- 大数阶乘(10000级别) 51Nod 1057
- 51nod 1057 N的阶乘(大数-划分)
- 51nod 1057 N的阶乘(大数问题)
- 51nod N的阶乘 (大数优化)
- 大数阶乘(10000)
- 1057 N的阶乘(大数阶乘)
- 51Nod 1057 N的阶乘(数论)
- 51Nod 1057 N的阶乘(基础题???数论???)
- 51nod 1189 阶乘分数(阶乘素因子分解)
- 51nod 1057 N的阶乘
- 51nod 1057 N的阶乘
- 51nod 1057 N的阶乘
- 51nod 1057 N的阶乘
- 51nod 1057 N的阶乘
- 51Nod 1057 N的阶乘
- 51nod 1057 N的阶乘
- 51Nod-1057-N的阶乘
- 51 nod 1057 n的阶乘
- linux c struct tm宏定义时有时报dereferencing pointer to incomplete type错误,可以将包含头文件改为#include <sys/timeb.h>
- 单向链表的实现
- springSecurity分离资源服务器分析
- Tricks(十九)—— 获得 list of lists 每一列的最大最小值
- import Tkinter的时候报错
- 大数阶乘(10000级别) 51Nod 1057
- java 继承中构造方法和类成员方法间的关系
- leetcode-Excel Sheet Column Title
- 反向代理分离资源服务器分析
- 使用TimerTask进行调度
- C/C++中static关键字的使用
- 第5周项目1 三角形3
- 码农小汪-Hibernate学习6-hibernate中Annocation修饰属性
- java 插入排序