一、链接
N!
二、题目
| Description | ||
| 请求N!(N<=10000),输出结果对10007取余 | ||
| Sample Input | ||
| 1 2 -1 | ||
| Sample Output | ||
| 1 2 | ||
| Source | ||
| ericxie | 
三、题意
输出阶乘结果
四、代码
c代码
#include<stdio.h>
int main()
{
	int n;
	while(scanf("%d",&n),n!=-1)
	{
		int t=1;
		for(int i=1;i<=n;i++)	t=t*i%10007;
		
		printf("%d\n",t);
	}
	
	return 0;
}c++代码
#include<iostream>
using namespace std;
int main()
{
	int n;
	while(scanf("%d",&n),n!=-1)
	{
		int t=1;
		for(int i=1;i<=n;i++)	t=t*i%10007;
		
		printf("%d\n",t);
	}
	
	return 0;
}五、总结
1.先给出两个递归不考虑时间复杂度的求阶乘的示例(因为那两个题目的n的取值小于10,结果不会很大):
819. 递归求阶乘
804. n的阶乘
2.基本思路是一边计算阶乘,一边取模,取模的第二个操作数10007可以保证每一次的计算结果小于10007,从而控制了数字的范围,就不会出现超时等情况
3.代码细节:多次输入,等于-1的时候结束程序,代码模板是这个
while(scanf("%d",&n),n!=-1)4.先把阶乘结果计算出来再取模,那个阶乘结果数字范围会非常大,int的数据范围是
-2^31 ~ 2^31-1即:-2147483648 - 2147483647
六、精美图片



















![[LeetCode - Python] 11.乘最多水的容器(Medium);26. 删除有序数组中的重复项(Easy)](https://img-blog.csdnimg.cn/d8583aed89c74b628cfa1e67253e2e79.png)
