HDU 2650 a math problem (Gaussian Integer Ring)

Source: Internet
Author: User

We call the set a Gaussian Integer Ring, where Z represents a general Integer Ring and an integer ring in a complex number field.

 

So what is a ring? It is called a ring that can satisfy its own nature after addition, subtraction, multiplication, and other operations.

 

 

Fan definition: Set, define the fan of a

 

Set, then

 

(1) It is a non-negative integer and

 

(2)

 

(3) If, then

 

 

 

Definition of inverse: Set, if exists, so, it is called the multiplication reversible element in, referred to as reversible element, and

It is called inverse.

 

A Gaussian Integer is a required and sufficient condition for reversible elements :. There are only four reversible elements, respectively: and

 

 

Definition: set and are two non-zero Gaussian integers. If there is a reversible element, the sum is equivalent and expressed as, in other words,

Equivalent to, that is, or

 

 

 

Gaussian Prime Number

Definition: set to a non-zero non-reversible element, which is called a Gaussian prime number. It refers to each factor, reversible element, or an equivalent Gaussian Integer.

 

Theorem:

(1) set as a Gaussian Integer, and as a prime number, it must be a Gaussian prime number.

(2) if it is a Gaussian prime number, the common element is also a Gaussian prime number.

 

 

How can we determine whether a Gaussian Integer is a Gaussian prime number? You can use the following method:

 

A Gaussian Integer is a prime number when and only when:

(1) One of A and B is zero, and the absolute value of the other is a prime number in the form of 4 N + 3;

(2) A and B are not zero, but are prime numbers;

 

With this conclusion, we can easily solve the hdu2650 problem.

 

Question: a math problem

 

Question: give, in which, determine whether it is a Gaussian prime number.

 

Analysis: This is actually the method used to determine the Gaussian prime number, but note that here, the normal situation is, in fact, the same,

Just change the condition "for prime number" to "for prime number". What if I change the title description? In the same way, you only need

You can change the judgment condition to a prime number. Because it is very large, write miller_rabin...


#include <stdio.h>#include <stdlib.h>#include <string.h>#include <iostream>const int Times=10;using namespace std;typedef long long LL;LL multi(LL a,LL b,LL m){     LL ans=0;     while(b)     {         if(b&1)         {             ans=(ans+a)%m;             b--;         }         b>>=1;         a=(a+a)%m;     }     return ans;}LL quick_mod(LL a,LL b,LL m){     LL ans=1;     a%=m;     while(b)     {         if(b&1)         {             ans=multi(ans,a,m);             b--;         }         b>>=1;         a=multi(a,a,m);     }     return ans;}bool Miller_Rabin(LL n){    if(n==2) return true;    if(n<2||!(n&1)) return false;    LL a,m=n-1,x,y;    int k=0;    while((m&1)==0)    {        k++;        m>>=1;    }    for(int i=0;i<Times;i++)    {        a=rand()%(n-1)+1;        x=quick_mod(a,m,n);        for(int j=0;j<k;j++)        {            y=multi(x,x,n);            if(y==1&&x!=1&&x!=n-1) return false;            x=y;        }        if(y!=1) return false;    }    return true;}int main(){    LL a,b;    while(~scanf("%I64d%I64d",&a,&b))    {        if(a==0)        {            if(b%4==3&&Miller_Rabin(b)) puts("Yes");            else  puts("No");        }        else        {            LL t=a*a+2*b*b;            if(Miller_Rabin(t)) puts("Yes");            else  puts("No");        }    }    return 0;}

The function of the following code is to find the prime factor of all Gaussian Integers of an integer.

# Include <iostream> # include <stdlib. h> # include <string. h> # include <stdio. h> # include <math. h> using namespace STD; const int n = 100005; int prime [N], p [N], K; int pri [N], top; int N; struct point {int A; int B; char character;} s [N]; int num; // filter prime void isprime () {k = 0; int I, J; memset (Prime, true, sizeof (PRIME); for (I = 2; I <n; I ++) {If (prime [I]) {P [k ++] = I; for (j = I + I; j <n; j + = I) {Prime [J] = false ;}}}} // prime factor decomposition void divide (Int n) {int I; Top = 0; for (I = 0; I <K; I ++) {If (N % P [I] = 0) {pri [top ++] = P [I]; N/= P [I]; while (N % P [I] = 0) {pri [top ++] = P [I]; N/= P [I] ;}} if (n> 1) pri [top ++] = N ;} // Gaussian prime number decomposition void part (INT prime) {int I; If (prime = 2) {s [num]. a = 1; s [num]. B = 1; s [num ++]. bytes = '+'; s [num]. a = 1; s [num]. B = 1; s [num ++]. else = '-';} else if (prime-1) % 4 = 0) {for (I = 1; I ++) {int u = int (SQRT (prime-I * 1.0) + 1e-5); If (u * u + I * I = prime) {s [num]. A = I; s [num]. B = u; s [num ++]. bytes = '+'; s [num]. A = I; s [num]. B = u; s [num ++]. token = '-'; break ;}} else {s [num]. A = prime; s [num ++]. B = 0 ;}} int CMP (const void * a, const void * B) {point * c = (point *) A; point * D = (point *) B; if (c->! = D-> A) return C-> A-D-> A; If (c-> B! = D-> B) return C-> B-d-> B; return C-> response = '-'? 1:-1;} void print (INT key) {printf ("% d", s [Key]. a); If (s [Key]. B = 0) return; If (s [Key]. B = 1) printf ("% CJ", s [Key]. alias); else printf ("% C % DJ", s [Key]. keys, s [Key]. b) ;}int main () {isprime (); int I, CAS = 1; while (~ Scanf ("% d", & N) {num = 0; divide (n); for (I = 0; I <top; I ++) part (PRI [I]); qsort (S, num, sizeof (point), CMP); printf ("case # % d:", CAS ++ ); print (0); for (I = 1; I <num; I ++) {If (s [I]. A = s [I-1]. A & S [I]. B = s [I-1]. B & S [I]. rows = s [I-1]. outputs) continue; if (I) printf (","); print (I) ;}puts ("") ;}return 0 ;}

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.