Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5391
Related Number theory conclusion:
Wilson's theorem-when and only if P is a prime number: (P-1)! ≡p-1 (mod p)
This problem at the beginning to see the time thought is the topic of violence, rapid factorial to take the mold, and then other problems do not come out to look at this problem,
Found to be able to find the law, when P is composite, the P factor can all be found in the number factor in front of P,
When P is prime, (p-1)!%p = p-1, try to write a bit, 2 A;
Because 4 is an exception, fear of other exceptions, within 100 small-scale run a bit of violence.
#include <stdio.h>#include<cmath>using namespacestd;intJudgeintN) { intm = sqrt (n+1); inti; for(i =2; I <= m; ++i) { if(n% i = =0){ return 0; } } if(i = = m +1) returnN-1;}intMain () {intT; intN; inttmp; scanf ("%d",&T); while(t--) {scanf ("%d",&N); if(N < -) {tmp=1; for(inti =1; I < n; ++i) {tmp= tmp * I%N; } printf ("%d\n", TMP); } Elseprintf ("%d\n", judge (n)); }}
Hdoj 5391 Zball in Tina town