题目链接: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. 修改sql2005字段

    alter table 表名 add 字段名 数据类型 default 默认值 增加:alter table AdCategory ADD SEOTitleNo varchar(50); 删除:ALT ...

  2. Visual Studio + SqlServer

    vs2010: http://pan.baidu.com/s/1eQrlUwU sqlServer2008: http://pan.baidu.com/s/1sjQbyk1

  3. 【20160924】GOCVHelper 图像增强部分(2)

       //填充孔洞     //fillholes     Mat fillHoles(Mat src){         Mat dst = getInnerHoles(src);          ...

  4. CSUFT 1004 This is Halloween: Saving Money

    1004: This is Halloween: Saving Money Time Limit: 1 Sec      Memory Limit: 128 MB Submit: 11      So ...

  5. hibernate的like用法(用占位符解决)

    原本我的写法:Query repeatClientQuery=querysession.createQuery("from ClientInfo as a " +"whe ...

  6. Radar之获取排列的UITexture数组

    1.定义UITexture二维数组 public UITexture[,] m_UITexture; 2.在 void start() 中分配内存 m_UITexture = , ]; 3.遍历排列的 ...

  7. android 入门 002 (拨打电话,发送短信)

    一.拨打电话 1.首先做好界面,代码如下: layout =>activity_main.xml 中 <LinearLayout xmlns:android="http://sc ...

  8. 编译android源码官方教程(3)下载代码

    https://source.android.com/source/downloading.html Downloading the Source IN THIS DOCUMENT Installin ...

  9. map的使用(自增)ret = map(lambda x : x+100 if x % 2 == 1 else x - 100, [1,2,3,4,5])

    #!/usr/bin/env python ret = map(lambda x : x+100 if x % 2 == 1 else x - 100, [1,2,3,4,5]) print(ret) ...

  10. NTT

    1 问题描述FFT问题解决的是复数域上的卷积.如果现在的问题是这样:给出两个整数数列$Ai,Bj,0\leq i\leq n-1,0\leq j\leq m-1$,以及素数$P$,计算新数列$Ci=( ...