b9113fced86a32cad0d8 @ 2024-11-12 15:47:26
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> ans;
vector<int> add(vector<int> a,vector<int> b){
vector<int> res;
res.resize(114514);
int x = 0;
for(int i = 0;i < max(a.size(),b.size());i++){
res[i] = a[i] + b[i] + x;
x = res[i] / 10;
res[i] %= 10;
}
return res;
}
vector<int> cf(vector<int> a,int b){
vector<int> res;
res.resize(114514);
int x = 0;
for(int i = 0;i < a.size();i++){
res[i] = a[i] * b + x;
x = res[i] / 10;
res[i] %= 10;
}
return res;
}
vector<int> fact(int x){
vector<int> res;
res[0] = 1;
for(int i = 1;i <= x;i++){
res = cf(res,i);
}
return res;
}
int main(){
cin>>n;
for(int i = 1;i <= n;i++){
ans = add(ans,fact(i));
}
bool flag = false;
for(int i = ans.size() - 1;i >= 0;i--){
if(ans[i] == 0 && !flag) continue;
else{
cout<<ans[i];
flag = true;
}
}
return 0;
}
编译器:TDM-GCC 4.9.2 64-bit Debug
by complete_binary_tree @ 2024-11-12 16:02:19
@b9113fced86a32cad0d8
我看你骨骼惊奇,为什么不给 ans
和 res
都 resize
一下。
还有开 会被臭死会 TLE,开小一点,
by Informatics_Wanderer @ 2024-11-12 16:08:16
@complete_binary_tree 那就只能开114了罢(悲