题目链接: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 大数阶乘的更多相关文章

  1. NYOJ题目28大数阶乘

    -------------------------------------祭出BigInteger AC代码: import java.math.BigInteger; import java.uti ...

  2. nyist28大数阶乘

    http://acm.nyist.net/JudgeOnline/problem.php?pid=28 大数阶乘 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 我们 ...

  3. nyoj___大数阶乘

    http://acm.nyist.net/JudgeOnline/problem.php?pid=28 大数阶乘 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 我们都知 ...

  4. 大数阶乘 nyoj

    大数阶乘 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?   输入 输入一个整数 ...

  5. 大数阶乘(c语言)

    大数阶乘.代码比较简单. #include<stdio.h> #include<string.h> #define MAXN 25000 // 如果你的阶乘N比较大,建议大一点 ...

  6. 【大数阶乘】NYOJ-28

    大数阶乘 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?   输入 输入一个整数 ...

  7. 【ACM】大数阶乘 - Java BigInteger实现

    大数阶乘 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?   输入 输入一个整数 ...

  8. 大数阶乘(c++实现)

    #include <iostream>using namespace std;#define N 1000int BigNumFactorial(int Num[], int n);voi ...

  9. HDU 1133 Buy the Ticket (数学、大数阶乘)

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

随机推荐

  1. 【转】Firefox快捷键

    转载地址: http://www.douban.com/note/140139119/ Ctrl + 数字键来打开第N个标签页这种还要先数完再到键盘上找数字Ctrl + Page Up = 激活左边一 ...

  2. c#线程创建

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  3. pandas安装过程中提示unable to find vcvarsall.bat的解决方法

    转载自:http://blog.csdn.net/qq_21144699/article/details/46849561 为这位老兄点赞 原帖参考:http://stackoverflow.com/ ...

  4. Python网络爬虫Scrapy框架研究 以及 代理设置

    地址:https://github.com/yidao620c/core-scrapy 例子:https://github.com/geekan/scrapy-examples 中文翻译文档: htt ...

  5. nautilus-open-terminal很有用的插件--鼠标右键打开终端

    1.1fedora安装# yum -y install nautilus-open-terminal安装nautilus-open-terminal,注销下X桌面即可ubuntu安装#sudo apt ...

  6. 将具有关联关系的两个表从hibernate查询出来转成json对象时报错

    第一篇文章: 相信大家做过JSON相关的东西对这个异常并不陌生,这个异常是由于JSONObject插件内部会无限拆解你传入的对象,直到没有可拆解为止,问题就在这,如果你传入的对象有外键关系,或者相互引 ...

  7. Android 内存分析工具 - LogCat GC

    一.GC_Reason 触发垃圾回收的回收的集中原因: 类型 描述 GC_CONCURRENT 内存使用将满时,并发的进行垃圾回收. GC_FOR_MALLOC 当内存已满应用尝试分配内存时会出触发垃 ...

  8. white的配置使用

    初次使用White来自动化测试10个9相加1.新建Visual C#->测试->单元测试项目2.在资源视图->引用,右键,添加引用,添加White的两个.dll文件3.在工程中添加命 ...

  9. MySQL基础(二)——DDL语句

    MySQL基础(二)--DDL语句 1.什么是DDL语句,以及DDL语句的作用 DDL语句时操作数据库对象的语句,这些操作包括create.drop.alter(创建.删除.修改)数据库对象. 2.基 ...

  10. Java CSV操作(导出和导入)

    Java CSV操作(导出和导入)  CSV是逗号分隔文件(Comma Separated Values)的首字母英文缩写,是一种用来存储数据的纯文本格式,通常用于电子表格或数据库软件.在 CSV文件 ...