阶乘和(优雅的递归) 题解:
注意数据范围,递归函数里的x也会爆int
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int n;
LL ans;
LL dfs(LL x)
{
if(x == 1) return x;
x = x * dfs(x - 1);
}
int main()
{
cin >> n;
for(int i = 1; i <= n; i ++)
ans += dfs(i);
cout << ans;
return 0;
}
登录后发布评论
暂无评论,来抢沙发