HDU 2674 N!Again(数学思维水题)

题目

 

//行开始看被吓一跳,那么大,没有头绪,

//看了解题报告,发现这是一道大大大的水题,,,,,
//2009 = 7 * 7 * 41
//对2009分解,看它有哪些质因子,它最大的质因子是41,那么对于大于等于41的数,直接输出0就行了。

 

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0)
            printf("1\n");
        else if(n>40)
            printf("0\n");
        else
        {
            int sum = n;
            while(--n)
            {
                sum = (sum * n) % 2009;
            }
            printf("%d\n",sum);
        }
    }
    return 0;
}
View Code

 

 

 

 

posted @ 2014-06-21 10:23  laiba2004  Views(127)  Comments(0Edit  收藏  举报