题目1076:N的阶乘(大数乘法)

题目链接:http://ac.jobdu.com/problem.php?pid=1076

详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus

参考代码:

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <cmath>
#define MAX_SIZE 10010
using namespace std;

int n;
int pos[MAX_SIZE];

int main(){
    while(~scanf("%d",&n)){
        memset(pos,0,sizeof(pos));
        if(0==n){
            printf("1\n");
            continue;
        }
        int i,j;
        int length = 1;
        pos[0]=1;
        for(i = 1 ; i <= n ; i++){
            int carry = 0;
            for(j = 0 ; j < length ; j++){
                pos[j] = pos[j] * i + carry;
                if(pos[j]>=10){
                    carry = pos[j]/10;
                    pos[j] = pos[j]%10;
                }
                else{
                    carry = 0;
                }
            }
            while(carry!=0){
                pos[length++] = carry % 10;
                carry/=10;
            }
        }
        for(i = MAX_SIZE ; i >= 0 ; i--){
            if(pos[i]!=0)
                break;
        }
        for(j = i ; j >= 0 ; j--){
            printf("%d",pos[j]);
        }
        printf("\n");
    }
    return 0;
}
/**************************************************************
    Problem: 1076
    User: zpfbuaa
    Language: C++
    Result: Accepted
    Time:1480 ms
    Memory:1560 kb
****************************************************************/
时间: 2024-08-02 18:05:52

题目1076:N的阶乘(大数乘法)的相关文章

51nod 1027大数乘法

题目链接:51nod 1027大数乘法 直接模板了. 1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 const int N = 1001; 5 const int DLEN = 4; 6 const int mod = 10000; 7 int alen, blen; 8 int ans_len; 9 char a1[N], b1[N]; 10 int a[600], b[600]; 11 int a

ACM学习历程—51NOD1028 大数乘法V2(FFT)

题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1028 题目大意就是求两个大数的乘法. 但是用普通的大数乘法,这个长度的大数肯定不行. 大数可以表示点值表示法,然后卷积乘法就能用FFT加速运算了. 这道题是来存模板的. 代码: #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath>

大数乘法的几种算法分析及比较(2014腾讯南京笔试题)

转自:http://blog.csdn.net/chhuach2005/article/details/21168179 1.题目 编写两个任意位数的大数相乘的程序,给出计算结果. 2.题目分析 该题相继被ACM.华为.腾讯等选作笔试.面试题,若无准备要写出这种程序,还是要花一定的时间的.故,觉得有必要深入研究一下.搜索了网上的大多数该类程序和算法,发现,大数乘法主要有模拟手工计算的普通大数乘法,分治算法和FFT算法.其中普通大数乘法占据了90%以上,其优点是空间复杂度低,实现简单,时间复杂度为

HDOJ-1042 N!(大数乘法)

http://acm.hdu.edu.cn/showproblem.php?pid=1042 题意清晰..简单明了开门见山的大数乘法.. 10000的阶乘有35000多位 数组有36000够了 # include <stdio.h> # include <string.h> # define MAX 36000 int BigNum[MAX], NowLen; void Multi(int number) { int Temp[MAX]={0}, Tlen = 0, t;//Tem

组合数学 + 大数乘法 + 大数除法 之 hdu 1261 字串数

//  [3/17/2015 JmingS] /* 此题可直接推导出公式: {(A1+A2+……+An)!} / {A1!A2!……An!} 由于 (12×26)! = 312! 只能通过数组来存储,所以又涉及『大数乘法』和『大数除法』, 大数实现的主要思想模拟手算,具体参考程序. */ 1 #include <iostream> 2 #include <cstdlib> 3 #include <cstdio> 4 #include <cstring> 5

[POJ] #1002# Exponentiation : 大数乘法

一. 题目 Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 156373   Accepted: 38086 Description Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of

51 Nod 1028 大数乘法 V2【Java大数乱搞】

1028 大数乘法 V2 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A,B的长度 <= 100000,A,B >= 0) Output 输出A * B Input示例 123456 234567 Output示例 28958703552 题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemI

51 Nod 1027 大数乘法【Java大数乱搞】

1027 大数乘法 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A,B的长度 <= 1000,A,B >= 0) Output 输出A * B Input示例 123456 234567 Output示例 28958703552 题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1027 分

九度OJ 1076 N的阶乘 (模拟)

题目1076:N的阶乘 时间限制:3 秒 内存限制:128 兆 特殊判题:否 提交:5244 解决:1786 题目描述: 输入一个正整数N,输出N的阶乘. 输入: 正整数N(0<=N<=1000) 输出: 输入可能包括多组数据,对于每一组输入数据,输出N的阶乘 样例输入: 4 5 15 样例输出: 24 120 1307674368000 #include<stdio.h> #include<string.h> int result[10000]; int main(i