[HDOJ5391] Zball in Tina town

Source: Internet
Author: User

Topic Connection: http://acm.hdu.edu.cn/showproblem.php?pid=5391

The Wilson theorem in number theory, the topic directly gives the language description of the expression of Wilson's theorem.

In elementary number theory, the Wilson theorem gives a sufficient and necessary condition for determining whether a natural count is a prime. That is: when and only if P is a prime number: (P-1)! ≡-1 (mod p), but because factorial is exploding, its conclusion is of little significance for practical operation.

The subject of special attention is n=4 time, to special sentence, is a trick. cout, too, will be timed out. Also, the subject data to the 2<=n<=10^9, need to consider is if the table, the complex is O (nsqrt (n)), if the separate sentence is O (n), so do not choose to hit the table. The code is as follows:

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<map>#include<Set>#include<cmath>#include<vector>#include<deque>#include<queue>using namespaceStd;typedefLong LongLL;intMain () {intT; scanf ("%d", &T);  while(t--) {        intFlag =0; intN; scanf ("%d", &N); intm =int(sqrt (n));  for(inti =2; I < m; i++)        {            if(n% i = =0) {flag++;  Break; }        }        if(n = =0|| n = =1) {printf ("1\n"); }        Else if(n = =2) {printf ("2\n"); }        Else if(!flag) {printf ("%d\n", N-1); }        Else{printf ("0\n"); }    }}
View Code

[HDOJ5391] 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.