#include<bits/stdc++.h>using namespace std;long long js(long long);int n;long long sum=0;int main(){cin>>n;for(int i=1;1<=n;i++)sum+=js(i);cout<<sum<<endl;return 0;}long long js(int n){long long s=1;for(int i=1;i<=n;i++)s*=i;return s;}openjudge中‘求10000以内n的阶乘’
1 回答
慕婉清6462132
TA贡献1804条经验 获得超2个赞
#include<bits/stdc++.h>
using namespace std;
long long js(long long);
int n;
long long sum=0;
int main() {
cin>>n;
for ( int i=1;1<=n;i++ )
sum+=js((long long)i);
cout<<sum<<endl;
return 0;
}
long long js(long long n) { long long s=1;
for ( int i=1;i<=n;i++ ) s*=i;
return s;
}
追问
Time Limit Exceeded!!!
- 1 回答
- 0 关注
- 654 浏览
添加回答
举报
0/150
提交
取消