http://acm.hdu.edu.cn/showproblem.php?pid=2674

n大于等于2009时取余为0,只要算2009前面的就ok

View Code
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
int ans,i;
while(~scanf("%d",&n))
{
ans=1;
if(n>=2009)
printf("0\n");
else
{
for(i=1;i<=n;i++)
{
ans*=i;
ans%=2009;
}
printf("%d\n",ans);
}
}
return 0;
}