wangshengchen @ 2024-09-08 10:19:43
#include <iostream>
using namespace std;
int main()
{
int N,A=1,B=0;
cin>>N;
for(int i=1;i<=N;i++)
{
A=1;
for(int m=1;m<=i;m++)
{
A*=m;
}
B+=A;
}
cout<<B;
return 0;
}
by adsd45666 @ 2024-09-08 10:27:37
结果太大,导致爆了int,本题正解为高精度。
by xuyangming @ 2024-09-08 10:31:09
@adsd45666 高精!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
by xuyangming @ 2024-09-08 10:32:13
#include<iostream>
using namespace std;
long long a[40005],lc[40005]={0,1};
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
int chang=40000,t=0;
while(lc[chang]==0&&chang>0)
{
chang--;
}
for(int j=1;j<=chang+1;j++)
{
lc[j]*=i;
}
for(int j=1;j<=chang+1;j++)
{
lc[j+1]+=lc[j]/10;
lc[j]%=10;
}
chang=40000;
while(lc[chang]==0&&chang>0)
{
chang--;
}
for(int j=1;j<=chang+1;j++)
{
a[j]+=lc[j];
a[j+1]+=a[j]/10;
a[j]%=10;
}
}
int chang=40000;
while(a[chang]==0&&chang>0)
{
chang--;
}
for(int i=chang;i>=1;i--)
{
cout<<a[i];
}
return 0;
}
by xuyangming @ 2024-09-08 10:32:39
关注一下吧
by adsd45666 @ 2024-09-08 10:36:52
@xuyangming 啊?Q我赣神魔,你去@贴主啊。
by xuyangming @ 2024-09-08 10:37:52
@adsd45666 弄错了,对不起
by wangshengchen @ 2024-09-08 11:09:21
@xuyangming 好的
by wangshengchen @ 2024-09-08 11:11:38
@xuyangming 你能教教我吗?(高精度)
by sea_bird @ 2024-09-15 10:26:20
像我一样多学一点再回来做
by yxszcxl @ 2024-09-17 17:47:54
@wangshengchen long long、unsigned long long也爆