nyoj 28 大数阶乘
题目链接:nyoj 28
就是个简单的高精度,只是一开始我打表超内存了,然后用了各种技巧硬是把内存缩到了题目要求以下(5w+kb),感觉挺爽的,代码如下:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const int M = ;
const int mod = 1e6; int b[M + ][], len[M + ]; inline void init(int n = M) {
b[][] = ; len[] = ;
for(int i = ; i <= n; ++i) {
int x = len[i - ];
int carry = ;
LL tmp;
for(int j = ; j < x; ++j) {
tmp = carry + (LL)b[i - ][j] * i;
b[i][j] = tmp % mod;
carry = tmp / mod;
}
while(carry) {
b[i][x++] = carry % mod;
carry /= mod;
}
len[i] = x;
}
} inline void print(const int &x) {
putchar(x / % + '');
putchar(x / % + '');
putchar(x / % + '');
putchar(x / % + '');
putchar(x / % + '');
putchar(x % + '');
} inline void output(const int &n) {
int i = len[n] - ;
const int &x = b[n][i];
printf("%d",x); for(--i; i >= ; --i)
print(b[n][i]);
puts("");
} int main() {
int m;
init();
while(~scanf("%d",&m))
output(m);
return ;
}
出题人原意应该不是让我们打表,而是每读入一个数重新计算一个数……吧:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cctype>
const int M = ; int b[][]; inline void solve(const int &n) {
b[][] = ;
int len = ;
for(int i = ; i <= n; ++i) {
int carry = , tmp;
for(int j = ; j < len; ++j) {
tmp = carry + b[!(i & )][j] * i;
b[i & ][j] = tmp % ;
carry = tmp / ;
}
while(carry) {
b[i & ][len++] = carry % ;
carry /= ;
}
}
for(int j = len - ; j >= ; --j)
putchar(b[n & ][j] + '');
puts("");
} template <typename T>
inline bool read(T &x) {
x = ;
char ch = getchar();
while(!isdigit(ch) && ch != EOF) ch = getchar();
if(ch == EOF) return ;
while(isdigit(ch)) {
x = x * + (ch - '');
ch = getchar();
}
return ;
} int main() {
int m;
while(read(m))
solve(m);
return ;
}
nyoj 28 大数阶乘的更多相关文章
- NYOJ题目28大数阶乘
-------------------------------------祭出BigInteger AC代码: import java.math.BigInteger; import java.uti ...
- nyist28大数阶乘
http://acm.nyist.net/JudgeOnline/problem.php?pid=28 大数阶乘 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 我们 ...
- nyoj___大数阶乘
http://acm.nyist.net/JudgeOnline/problem.php?pid=28 大数阶乘 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 我们都知 ...
- 大数阶乘 nyoj
大数阶乘 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它? 输入 输入一个整数 ...
- 大数阶乘(c语言)
大数阶乘.代码比较简单. #include<stdio.h> #include<string.h> #define MAXN 25000 // 如果你的阶乘N比较大,建议大一点 ...
- 【大数阶乘】NYOJ-28
大数阶乘 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它? 输入 输入一个整数 ...
- 【ACM】大数阶乘 - Java BigInteger实现
大数阶乘 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它? 输入 输入一个整数 ...
- 大数阶乘(c++实现)
#include <iostream>using namespace std;#define N 1000int BigNumFactorial(int Num[], int n);voi ...
- HDU 1133 Buy the Ticket (数学、大数阶乘)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
随机推荐
- ACM第二站————归并排序
转载请注明出处,谢谢!http://www.cnblogs.com/Asimple/p/5459664.html 归并排序————二分的思想 以中间的数为基准,每次排序都将比其小[升序排](大[降序排 ...
- Spring MVC 的汉字乱码问题
在web.xml文件加入 <filter> <filter-name>characterEncodingFilter</filter-name> <filte ...
- HDU 4706:Children's Day
Children's Day Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- Pie(二分POJ3122)
Pie Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12985 Accepted: 4490 Special Ju ...
- MySQL 数据库发展历程及缺点
传统关系数据库的瓶颈 传统的关系数据库具有不错的性能,高稳定型,久经历史考验,而且使用简单,功能强大,同时也积累了大量的成功案例.在互联网领域,MySQL成为了绝对靠前的王者,毫不夸张的说,MySQL ...
- Android各种获取Context方法
首先讲一讲这四个函数的区别,后面还有我对context的一些理解区别如下所示: 原文链接http://stackoverflow.com/questions/6854265/getapplicatio ...
- CXF集成spring做webservice接口
一 . cxf 的jar包 1.cxf-2.3.3.jar 2.wsdl4j-1.6.2.jar 3.wss4j-1.5.11.jar 4.wstx-asl-3.2.0.jar 5.XmlSchema ...
- MUI 微信 和支付宝支付 (前台代码)
<!-- 校园公告详情界面 用于显示校园公告的详情信息 在校园公告界面点击某一条目后 进入本界面查看详情 --> <!DOCTYPE html> <html> &l ...
- Spring 框架 详解 (二)
Spring的入门的程序: 1.1.1 下载Spring的开发包: spring-framework-3.2.0.RELEASE-dist.zip ---Spring开发包 * docs :sprin ...
- 【leetcode❤python】70. Climbing Stairs
#Method1:动态规划##当有n个台阶时,可供选择的走法可以分两类:###1,先跨一阶再跨完剩下n-1阶:###2,先跨2阶再跨完剩下n-2阶.###所以n阶的不同走法的数目是n-1阶和n-2阶的 ...