【杭电】[2674]N!Again

文章字数:107

问题描述

问题分析

同余定理的运用 理解同余定理就好了 主要是这个:

(a+b)%c=(a%c+b%c)%c

然后代码就很好写了:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include<stdio.h>
int main() {
	int N,s,p;
	int i;
	while(scanf("%d",&N)!=EOF) {
		if(N>=49)
			printf("0\n");
		else {
			for(i=s=1; i<=N; i++) {
				s*=i;
				s%=2009;
			}
			printf("%d\n",s);
		}
	}
	return 0;
}

题目地址:【杭电】[2674]N!Again

该内容采用 CC BY-NC-SA 4.0 许可协议。

如果对您有帮助或存在意见建议,欢迎在下方评论交流。

加载中...