HDU 2650 A math problem Gaussian Integer Determination

Source: Internet
Author: User

HDU 2650 A math problem Gaussian Integer Determination

 

 

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...


 

 

import java.text.DecimalFormat;import java.util.ArrayDeque;import java.io.BufferedReader;  import java.io.InputStreamReader;  import java.io.PrintWriter;  import java.math.BigInteger;  import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.Comparator;import java.util.Deque;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.Map;import java.util.PriorityQueue;import java.util.Random;import java.util.Scanner;import java.util.Stack;import java.util.StringTokenizer;import java.util.TreeMap;import java.util.TreeSet;import java.util.Queue;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;public class Main{long multi(long a,long b,long m)  {       long ans=0;       while(b>0)       {           if((b&1)!=0)           {               ans=(ans+a)%m;               b--;           }           b/=2;         a=(a+a)%m;       }       return ans;  }    long quick_mod(long a,long b,long m)  {       long ans=1;       a%=m;       while(b>0)       {           if((b&1)!=0)           {               ans=multi(ans,a,m);               b--;           }           b/=2;           a=multi(a,a,m);       }       return ans;  }    boolean MillarRabin(long n)  {      if(n==2) return true;      if(n<2||0==(n&1)) return false;      long a,m=n-1,x,y = 0;      int k=0;      while((m&1)==0)      {          k++;          m/=2;      }      for(int i=0;i<10;i++)      {          a=abs(rand.nextLong())%(n-1)+1;         x=quick_mod(a,m,n);          for(int j=0;j
 
  > 1;if (A[mid] <= val) {l = mid + 1;} else {pos = mid;r = mid - 1;}}return pos;}int Pow(int x, int y) {int ans = 1;while (y > 0) {if ((y & 1) > 0)ans *= x;y >>= 1;x = x * x;}return ans;}double Pow(double x, int y) {double ans = 1;while (y > 0) {if ((y & 1) > 0)ans *= x;y >>= 1;x = x * x;}return ans;}int Pow_Mod(int x, int y, int mod) {int ans = 1;while (y > 0) {if ((y & 1) > 0)ans *= x;ans %= mod;y >>= 1;x = x * x;x %= mod;}return ans;}long Pow(long x, long y) {long ans = 1;while (y > 0) {if ((y & 1) > 0)ans *= x;y >>= 1;x = x * x;}return ans;}long Pow_Mod(long x, long y, long mod) {long ans = 1;while (y > 0) {if ((y & 1) > 0)ans *= x;ans %= mod;y >>= 1;x = x * x;x %= mod;}return ans;}int Gcd(int x, int y){if(x>y){int tmp = x; x = y; y = tmp;}while(x>0){y %= x;int tmp = x; x = y; y = tmp;}return y;}long Gcd(long x, long y){if(x>y){long tmp = x; x = y; y = tmp;}while(x>0){y %= x;long tmp = x; x = y; y = tmp;}return y;}int Lcm(int x, int y){return x/Gcd(x, y)*y;}long Lcm(long x, long y){return x/Gcd(x, y)*y;}int max(int x, int y) {return x > y ? x : y;}int min(int x, int y) {return x < y ? x : y;}double max(double x, double y) {return x > y ? x : y;}double min(double x, double y) {return x < y ? x : y;}long max(long x, long y) {return x > y ? x : y;}long min(long x, long y) {return x < y ? x : y;}int abs(int x) {return x > 0 ? x : -x;}double abs(double x) {return x > 0 ? x : -x;}long abs(long x) {return x > 0 ? x : -x;}boolean zero(double x) {return abs(x) < eps;}double sin(double x){return Math.sin(x);}double cos(double x){return Math.cos(x);}double tan(double x){return Math.tan(x);}double sqrt(double x){return Math.sqrt(x);}}
 


 

Related Article

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.