全WA了,DaoLao求改正

P1009 [NOIP1998 普及组] 阶乘之和

King_of_Hell @ 2022-12-07 22:07:01

rt

#include<bits/stdc++.h>
using namespace std;
unsigned long long fun(unsigned long long n)
{
    unsigned long long s=1;
    for(int i=1;i<=n;++i)
    {
        s*=i;
    }
    return s;
}
int main()
{
    unsigned long long  n,f=0;
    cin>>n;
    for(unsigned long long i=1;i<=n;++i)
    {
        f=+fun(i);
    }
    cout<<f;
    return 0;
}

by register_new @ 2022-12-07 22:10:46

@spyzyjs 你看一下这道题范围,要用高精啊,你的unsigned long long一下子就爆了


by VitrelosTia @ 2022-12-07 22:14:29

@spyzyjs

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


by King_of_Hell @ 2022-12-07 22:20:39

我嫌高精代码长......


by __er @ 2022-12-07 22:57:26

@spyzyjs python


by __er @ 2022-12-07 22:58:15

@spyzyjs

n=eval(input())     
ans=0
for i in range(1,n+1):
    s=1
    for j in range(1,i+1):
        s*=j
    ans+=s
print(ans)

by King_of_Hell @ 2022-12-08 07:56:59

@__er

谢谢


|