This problem has a small trick, that is, since it is n!, then to 2009 to balance, as long as more than 2009!, then must be 0, in a careful thought will find, at all, not to 2009, as long as the maximum of 2009 factorization on the line, why? Because the maximum factorization is the largest one can not be divisible by 2009, 2009 of the maximum factorization is 41, that is, as long as the factorial of more than 41 divisible by 2009, because the factorial of 41 can be divisible, 42! = 42 * 41!, so more than 41 is all 0, then the problem is simple
The code is as follows:
1#include <iostream>2#include <cstdio>3 using namespacestd;4 5 intdp[ $];6 intMain ()7 {8 9dp[0] =1;Tendp[1] =1; Onedp[2] =2; A for(inti =3; I < $; i++) - { -Dp[i] = dp[i-1] * I% the; the } - intN; - while(~SCANF ("%d", &N)) - { + if(N >= A) -Puts"0"); + Else Aprintf"%d\n", Dp[n]); at } - return 0; -}
HDU-2674 N! Again (Little Tricks)