问题标题: 洛谷:P1009 阶乘之和

0
0
已解决
张恩泽
张恩泽
高级天翼
高级天翼

题目描述

用高精度计算出S=1!+2!+3!+…+n!(n≤50)S=1!+2!+3!+…+n! (n≤50)S=1!+2!+3!+…+n!(n≤50)

其中“!”表示阶乘,例如:5!=5×4×3×2×15!=5 \times 4 \times 3 \times 2 \times 15!=5×4×3×2×1。

输入格式

一个正整数NNN。

输出格式

一个正整数SSS,表示计算结果。

输入输出样例

输入 #1

3

输出 #1

9

说明/提示

注,《深入浅出基础篇》中使用本题作为例题,但是其数据范围只有 n≤20n\le20n≤20,使用书中的代码无法通过本题。

如果希望通过本题,请继续学习第八章高精度的知识。

 

    #include<iostream>
    using namespace std;
    long long jc(int n)
    {
    	long long a=1;
    	for(int i=1;i<=n;i++)
    	{
    		a*=i;
    	}
    	return a;
    }
    int main()
    {
    	int n;
    	long long sum=0;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	{
    		sum+=jc(i);
    	}
    	cout<<sum;
    	return 0;
    }

本来想氵一题的,但发现在酷町堂里AC了,但到洛谷就WA了,两个点

张恩泽在2020-12-23 18:40:04追加了内容

复制不了的话,QQ有一个截图识字的功能【疯狂明示】

张恩泽在2020-12-25 21:19:24追加了内容

哈,居然还有一个点!!!!

@黄依成 

 


1
已采纳
黄依成
黄依成
中级天翼
中级天翼

这道题要用高精度的,酷町堂数据比较水

送你一个表:

string a[105]={"0","1","3","9","33","153","873","5913","46233","409113","4037913","43954713","522956313","6749977113","93928268313","1401602636313","22324392524313","378011820620313","6780385526348313","128425485935180313","2561327494111820313","53652269665821260313","1177652997443428940313","27029669736328405580313","647478071469567844940313","16158688114800553828940313","419450149241406189412940313","11308319599659758350180940313","316196664211373618851684940313","9157958657951075573395300940313","274410818470142134209703780940313","8497249472648064951935266660940313","271628086406341595119153278820940313","8954945705218228090637347680100940313","304187744744822368938255957323620940313","10637335711130967298604907294846820940313","382630662501032184766604355445682020940313","14146383753727377231082583937026584420940313","537169001220328488991089808037100875620940313","20935051082417771847631371547939998232420940313","836850334330315506193242641144055892504420940313","34289376947494122614363304694584807557656420940313","1439295494700374021157505910939096377494040420940313","61854558558074209658512637979453093884758552420940313","2720126133346522977702138448994068984204397080420940313","122342346998826717539665299944651784048588130840420940313","5624964506810915667389970728744906677010239883800420940313","264248206017979096310354325882356886646207872272920420940313","12678163798554051767172643373255731925167694226950680420940313","620960027832821612639424806694551108812720525606160920420940313","31035053229546199656252032972759319953190362094566672920420940313"};

至于怎么用,你肯定知道的

黄依成在2020-12-23 18:40:44追加了内容

啊这复制不了

0
陈振轩
陈振轩
高级光能
高级光能

加上高精代码吧。。。

什么,你不会?

不然就用简洁的Python(自带高精yyds)

把你写的代码转换成Python的代码

然后就可以AC了

什么,你不会?

那我就无能为力了

毕竟我使用Python AC的

0
臧鸿志
臧鸿志
初级天翼
初级天翼

先写出递推关系式f[i]=f[i-1]*i,sum+=f[i];

再用高精度乘法和高精度加法替换这里乘法和加法,注意f[0]="1"

0
黄硕梁
黄硕梁
初级天翼
初级天翼

我还不知道怎么登洛谷

我要回答