POJ3641 pseudoprime Numbers (Fast Power + prime number judgment)

Source: Internet
Author: User

POJ3641 pseudoprime Numbers

P is the condition of pseudoprime numbers: P is composite, (p^a)%p=a; So first, the prime judgment, then the fast power.

This is a simplified version of the Great white P122 Carmichael number.

  

/** created:2016 March 30 22:32 15 Second Wednesday * author:akrusher**/#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<ctime>#include<iostream>#include<algorithm>#include<string>#include<vector>#include<deque>#include<list>#include<Set>#include<map>#include<stack>#include<queue>#include<numeric>#include<iomanip>#include<bitset>#include<sstream>#include<fstream>using namespacestd;#defineRep (i,a,n) for (int i=a;i<n;i++)#definePer (i,a,n) for (int i=n-1;i>=a;i--)#defineIn (n) scanf ("%d",& (n))#defineIn2 (X1,X2) scanf ("%d%d",& (x1),& (x2))#defineINLL (n) scanf ("%i64d",& (n))#defineInll2 (X1,X2) scanf ("%i64d%i64d",& (x1),& (x2))#defineINLLD (n) scanf ("%lld",& (n))#defineInlld2 (X1,X2) scanf ("%lld%lld",& (x1),& (x2))#defineINF (n) scanf ("%f",& (n))#defineInf2 (X1,X2) scanf ("%f%f",& (x1),& (x2))#defineINLF (n) scanf ("%lf",& (n))#defineINLF2 (X1,X2) scanf ("%lf%lf",& (x1),& (x2))#defineInc (STR) scanf ("%c",& (str))#defineINS (str) scanf ("%s", (str))#defineOut (x) printf ("%d\n", (x))#defineOut2 (x1,x2) printf ("%d%d\n", (x1), (x2))#defineOutf (x) printf ("%f\n", (x))#defineOUTLF (x) printf ("%lf\n", (x))#defineOUTLF2 (x1,x2) printf ("%lf%lf\n", (x1), (x2));#defineOUTLL (x) printf ("%i64d\n", (x))#defineOUTLLD (x) printf ("%lld\n", (x))#defineOUTC (str) printf ("%c\n", (str))#definePB Push_back#defineMP Make_pair#defineFi first#defineSe Second#defineSZ (x) ((int) (x). Size ())#defineMem (x, y) memset (x,y,sizeof (×));typedef vector<int>Vec;typedefLong LongLl;typedef pair<int,int>P;Const intdx[4]={1,0,-1,0},dy[4]={0,1,0,-1};Const intinf=0x3f3f3f3f; ll Mod;ll Powmod (ll A,ll b) {ll res=1; a%=mod; for(; b;b>>=1){if(b&1) Res=res*a%mod;a=a*a%mod;}returnRes;}Const BOOLAc=true;BOOLIs_prime (intN) {     for(intI=2; i*i<=n;i++){        if(n%i==0)return false; }    returnn!=1;}intMain () {ll a,p,ans;  while(Inlld2 (p,a) = =2){    if(p==0&&a==0) Break; MoD=p; Ans=Powmod (a,p); if(!is_prime (P) &&ans==a) {printf ("yes\n"); }        Else{printf ("no\n"); }    }    return 0;}

POJ3641 pseudoprime Numbers (Fast Power + prime number judgment)

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.