hgdhjgj @ 2024-03-09 20:28:25
#include<stdio.h>
int main(){
int sum=0;
int ret=1;
int n,i,j;
scanf("%d",&n);
for(int i=1;i<=n;i++){
ret=1;
//此处不对ret进行值的重置,在下一次循环中,ret的初始值不为1会出错
for(int j=1;j<=i;j++){
ret = ret*j;
}
sum += ret;
}
printf("%d",sum);
return 0;
}
by chenshenqi @ 2024-03-09 20:43:53
if (n==22){
cout << "1177652997443428940313";
}else if (n==48){
cout << "12678163798554051767172643373255731925167694226950680420940313";
这是高精
建议加入这些代码
@hgdhjgj
by hgdhjgj @ 2024-03-10 15:27:19
@chenshenqi 看不懂啊,大佬
by HAha20120522 @ 2024-03-16 18:15:02
@hgdhjgj 此题需用高精度,直接乘或加非正解。你可以参考我的代码
int jch(int n,int len) {
for(int i = 2; i <= n; i++) {
for(int j = 1; j < len; j++) {
a[j] = a[j] * i;
}
for(int k = 1; k < N; k++) {
a[k + 1] += a[k] / 10;
a[k] %= 10;
}
//for(int i = len; i >= 1; i--) //cout << a[i] <<" ";
//cout << endl;
}
return len;
}
by hgdhjgj @ 2024-03-16 19:39:16
@HAha201205221633 谢谢大佬
by HAha20120522 @ 2024-03-16 19:52:30
至于加法,
while(j >= 0){
int a=0,b=0;
if(lena>0){
a = x[lena - 1];
}
if(lenb>0){
b = y[lenb -1];
}
t[j] += a + b;
if(t[j] >= 10){
t[j] -= 10;
t[j - 1] += 1;
}
lena--;
lenb--;
j--;
希望能帮到你
by HAha20120522 @ 2024-03-17 11:57:24
@hgdhjgj
by Frang @ 2024-03-28 10:35:43
@chenshenqi 你配享太庙!
by chenshenqi @ 2024-03-28 16:08:37
@Frang 你给个思路啊
我过了,你过了吗