KangarooGao @ 2023-10-24 14:22:43
#include<iostream>
#include<iomanip>
#include<string>
#include<cmath>
using namespace std;
int main(){
int n;
long double sum = 0;
cin >> n;
long double currentFactorial = 1;
for(int i = 1; i <= n; ++i) {
currentFactorial *= i;
sum += currentFactorial;
}
cout << fixed << setprecision(0) << sum << endl;
return 0;
}
by 2021zjhs005 @ 2023-10-24 14:28:01
有个发现:
你这个代码,输入 31035053229546199652450892297664579467066897756393885159194099712
而
31035053229546199656252032972759319953190362094566672920420940313
建议还是使用高精度来完成。
by KangarooGao @ 2023-10-24 15:11:15
好的,谢谢。发现其实n=22时就错了。