HDUOJ1042-N!

来源:互联网 发布:模板小偷帝国cms 编辑:程序博客网 时间:2024/06/10 22:47

大数阶乘问题

#include <iostream>#include <cstring>using namespace std;const int MAXN = 40001;int a[MAXN] = {0};void BigFactorial(int m){    int i, j;    int carry;    int temp;    a[MAXN - 1] = 1;        for (i = 2; i <= m; i++) {        carry = 0;        for (j = MAXN - 1; j >= 0; j--) {            temp = a[j] * i + carry;            a[j] = temp % 10;            carry = temp / 10;        }    }        for (i = 0; i < MAXN; i++) {        if (a[i])            break;    }        for ( ; i < MAXN; i++)        cout << a[i];        cout << endl;        memset(a, 0, sizeof(int) * MAXN);}int main(){    int n;    while (cin >> n)        BigFactorial(n);        return 0;}


0 0