大数阶乘(10000级别) 51Nod 1057
2016-04-01 21:35
381 查看
题目链接:
51Nod 1057问题描述
输入N求N的阶乘的准确值。Input
输入N(1 <= N <= 10000)Output
输出N的阶乘Input示例
5Output示例
120思路:
一百万亿进制(14个0),大数相乘,求阶乘代码:
#include<iostream> #include<stdio.h> #include<algorithm> #define LL long long using namespace std; #define mod 100000000000000;//14个0 const int N = 1000086; LL a ; 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; }
相关文章推荐
- 1.m分解阶乘之和
- 2.几种递推数
- 3.欧拉函数
- 4.快速幂模m算法
- 5.扩展欧几里得&&中国剩余定理
- 6.数论_web
- Project Euler Problem 387 - Harshad Numbers - 深度优先
- 编程之美2015初赛A
- 数论题集
- 原根
- 阶与原根学习笔记
- HDU 1299 Diophantus of Alexandria
- Leftmost Digit(HDU 1060)
- Rightmost Digit(HDU 1061)
- Python-在奇数中寻找素数
- ZOJ 2674 Strange Limit 欧拉定理
- LeetCode-Palindrome Number
- 组合数求模总结
- Sicily 1047 Super Snooker
- 【数论】组合数求模