luca66 @ 2024-12-21 09:28:09
#include <bits/stdc++.h>
using namespace std;
signed long long n,sum=1;
signed main(){
cin >> n;
for(int i=n;i>1;i--){
sum*=i;
}
cout << sum;
return 0;
}
by __zyh__ @ 2024-12-21 09:40:30
孩子,这道题要用高精。
by rainy_morning @ 2024-12-21 09:44:48
用高精度,不然会爆
by luca66 @ 2024-12-21 09:45:30
OKOK,我看题解都是用高精,我就想把它开大亿点
by leoqing @ 2024-12-21 09:53:48
最主要问题是:S=1!+2!+3!+⋯+n!( n ≤ 50 n≤50)。算的是和呀!不是单求一个....
by tangyiqi @ 2024-12-21 16:35:28
@luca66
还是看我的吧。
#include <bits/stdc++.h>
using namespace std;
int n,a[500],t[500];
int add(int len);
int multi(int k,int len);
int main(){
scanf("%d",&n);
int lenf = 1,lens = 1;
a[1] = 1;
for(int i = 1;i<=n;i++){
lenf = multi(i,lenf);
lens = max(lenf,lens);
lens = add(lens);
}
for(int i = lens;i>0;i--)printf("%d",t[i]);
return 0;
}
int add(int len){
for(int i = 1;i<=len;i++){
t[i]+=a[i];
t[i+1]+=t[i]/10;
t[i]%=10;
}
if(t[len+1]>0)len++;
return len;
}
int multi(int k,int len){
for(int i = 1;i<=len;i++)a[i]*=k;
for(int i = 1;i<=len;i++)
if(a[i]>9){
a[i+1]+=a[i]/10;
a[i]%=10;
if(i == len)len++;
}
return len;
}
求关,求加团
by huyouxi @ 2024-12-22 08:15:16
@luca66你试试50,可能会输出-3473657201376232935
by yl_ykf @ 2024-12-29 21:50:50
(你是如何算出49的结果的呢...
by Mitsui_Hisashi @ 2025-01-03 20:40:00
@luca66 where is "gaojing"?