Jerry0417 @ 2023-04-08 17:35:18
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
long long sum=0,cnt=1;
for(int i=1;i<=n;i++){
cnt=1;
for(int j=1;j<=i;j++){
cnt*=j;
}
sum+=cnt;
}
cout<<sum;
}
by chaynflow @ 2023-04-08 17:40:37
朋友,你学高精度了吗?没学做不了吧,你看说明提示了吗?
by jasonxue2012 @ 2023-04-08 18:02:56
这题需要高精度
by xxc123 @ 2023-04-10 22:11:56
求关注
#include<iostream>
using namespace std;
int a[1001],b[1001];
void add()
{
int t=0;
for(int i=1000;i>=1;i--)
{
b[i]=b[i]+a[i]+t;
t=b[i]/10;
b[i]%=10;
}
}
void multiplication(int x)
{
int t=0;
for(int i=1000;i>=1;i--)
{
a[i]=a[i]*x+t;
t=a[i]/10;
a[i]%=10;
}
}
void print()
{
int flag=0;
for(int i=1;i<=1000;i++)
{
if(b[i]!=0) flag=1;
if(flag) cout<<b[i];
}
}
int main()
{
a[1000]=b[1000]=1;
int n;
cin>>n;
for(int i=2;i<=n;i++)
{
multiplication(i);
add();
}
print();
return 0;
}
从末尾算,a是阶乘积,s是和
by xxc123 @ 2023-04-10 22:12:06
@Jerry0417