Hdoj 5391 Zball in Tina town

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.