加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

HDU1042 求N!

发布时间:2020-12-14 03:36:37 所属栏目:大数据 来源:网络整理
导读:很早就看了大数,本来今天自己写了个大数类想自己用一下,结果,,,,坑爹的HDUOJ限制32M内存,,,,32M,,,打表不够打的。。。 其实压根没必要用4位的大数,直接上1位的来(其实差不多) #include string.h#include stdio.h#include math.h#include std

很早就看了大数,本来今天自己写了个大数类想自己用一下,结果,,,,坑爹的HDUOJ限制32M内存,,,,32M,,,打表不够打的。。。

其实压根没必要用4位的大数,直接上1位的来(其实差不多)

#include <string.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int a[44444];
int main()
{
    int N;
    while(scanf("%d",&N)!=EOF)
    {
        int len=1;
        a[0]=1;
        if(N<=1)
            printf("1n");
        else
        {
            int carry=0;
            for(int i=2;i<=N;i++)
            {
                for(int j=0;j<len;j++)
                {
                    carry+=i*a[j];
                    a[j]=carry%10;
                    carry/=10;
                }
                while(carry)
                {
                    a[len]=carry%10;
                    carry/=10;
                    len++;
                }
            }
            for(int i=len-1;i>=0;i--)
            {
                printf("%d",a[i]);
            }
            printf("n");
        }
    }
    return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读