游客 Signup | Login
中文 | En

1306 - C语言程序设计教程(第三版)课后习题6.4

求Sn=1!+2!+3!+4!+5!+…+n!之值,其中n是一个数字。

Input

n

Output

Examples

Input

5

Output

153

Hint

n的取值比较大,Sn需要定义成long long型,输出使用%lld

如果使用VC6调试,Sn定义成__int64,输出使用%I64d,提交时记得改回来。

Solution C++

#include<iostream>
using namespace std;
int main()
{
	int n,t=1;
	cin>>n;
	long long sn=0;
	for (int i=1; i<=n; i++)
	{
		t*=i;
		sn+=t;
	}
	cout<<sn<<endl;
	return 0;
}

Hint

n的取值比较大,Sn需要定义成long long型,输出使用%lld

如果使用VC6调试,Sn定义成__int64,输出使用%I64d,提交时记得改回来。

Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题