#include <iostream>using namespace std;int main() {long long s,n,i,j,p;s=0;cin>>n;//从1累加到n for(i=1;i<=n;i++) { p=1; for(j=1;j<=i;j++) p*=j; s+=p; } cout<<s<<endl;return 0; }
测试结果:
时间: 2024-10-11 09:15:18
#include <iostream>using namespace std;int main() {long long s,n,i,j,p;s=0;cin>>n;//从1累加到n for(i=1;i<=n;i++) { p=1; for(j=1;j<=i;j++) p*=j; s+=p; } cout<<s<<endl;return 0; }
测试结果: