Java BigInteger Value Check isRootInQuadraticResidues(BigInteger n, BigInteger p)

Here you can find the source of isRootInQuadraticResidues(BigInteger n, BigInteger p)

Description

is Root In Quadratic Residues

License

Apache License

Declaration

public static boolean isRootInQuadraticResidues(BigInteger n, BigInteger p) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.math.BigInteger;

public class Main {
    public static boolean isRootInQuadraticResidues(BigInteger n, BigInteger p) {
        BigInteger tow = BigInteger.valueOf(2);
        BigInteger x = n.mod(p);/*from   w  w  w.  jav  a2s . c  o  m*/
        if (p.equals(tow)) {
            return x.mod(tow).equals(BigInteger.ONE);
        }
        BigInteger exponent = p.subtract(BigInteger.ONE).divide(tow);
        return x.modPow(exponent, p).equals(BigInteger.ONE);
    }
}

Related

  1. isOdd(BigInteger x)
  2. isPerfectCubic(BigInteger n)
  3. isPositive(final BigInteger value)
  4. isPowerOfTwo(BigInteger bintValue)
  5. isPowerOfTwo(BigInteger x)
  6. isSqrtXXX(BigInteger n, BigInteger root)
  7. isZero(BigInteger value)