题目链接: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. 【转】MYSQL入门学习之五:MYSQL的字符集

    转载地址:http://www.2cto.com/database/201212/175541.html MySQL的字符集支持(Character Set Support)有两个方面:字符集(Cha ...

  2. 【转】介绍设置Session失效的几种方法

    转载地址:http://developer.51cto.com/art/201106/269493.htm Session对象是HttpSessionState的一个实例.该类为当前用户会话提供信息, ...

  3. jqeury轮播

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  4. Wormholes 分类: POJ 2015-07-14 20:21 21人阅读 评论(0) 收藏

    Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 35235   Accepted: 12861 Descr ...

  5. 【20160924】GOCVHelper 图像增强部分(1)

    图像增强是图像处理的第一步.这里集成了一些实际使用过程中有用的函数.   //读取灰度或彩色图片到灰度     Mat imread2gray(string path){         Mat sr ...

  6. Codeforces Round #366 (Div. 2) B

    Description Peter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a ...

  7. Keytool生成csr

    一. 首先生成密钥库 keytool -genkey -keyalg RSA -keysize 4096 -keystore c:\keystore4096.jks 二.生成csr keytool - ...

  8. fffffffffff

    create proc partPage114 @n int,--每页数量 @page int, --页码从0开始 @Mainkey int as declare @sql nvarchar(1000 ...

  9. PostGIS_导入shp格式的数据

    1.导入shp到PostGIS 开启PostGIS shp Loader,如下图: 打开View connection details....输入连接数据库的参数,如下: 连接成功后,点击Add Fi ...

  10. 粒子群优化算法(Particle Swarm Optimization)

    粒子群算法的思想源于对鸟/鱼群捕食行为的研究,模拟鸟集群飞行觅食的行为,鸟之间通过集体的协作使群体达到最优目的,是一种基于Swarm Intelligence的优化方法.它没有遗传算法的"交 ...