Package java.math

Examples of java.math.BigInteger.divide()


      if (b.signum() == -1)
        temp = temp.add(BigInteger.ONE).negate();
      temp = temp.add(a);
      if (temp.signum() == -1)
        temp = temp.subtract(c.subtract(BigInteger.ONE));
      return temp.divide(c);
    }
   
   
    public boolean equals(Object obj) {
      if (!(obj instanceof QuadraticSurd))
View Full Code Here


  // Returns 1^2 + 2^2 + 3^2 + ... + n^2 mod MODULUS
  private static long sumSquaresMod(long n) {
    BigInteger x = BigInteger.valueOf(n);
    BigInteger y = x.multiply(x.add(BigInteger.ONE));
    y = y.multiply(x.shiftLeft(1).add(BigInteger.ONE));
    y = y.divide(SIX_BI);
    y = y.mod(MODULUS_BI);
    return y.longValue();
  }
 
}
View Full Code Here

        {
            v = ZERO;
            while (!a.testBit(0))
            { // a is even
                v = v.add(ONE);
                a = a.divide(TWO);
            }
            if (v.testBit(0))
            {
                k = k * jacobiTable[b.intValue() & 7];
            }
View Full Code Here

        for (int i = 0; i < result.size(); ++ i) {
            BigInteger a = result.get(i);
            ArrayList <Integer> buffer = new ArrayList <Integer>();
            while (a.compareTo(BigInteger.ZERO) > 0) {
                buffer.add((int)a.remainder(BigInteger.valueOf(b)).longValue());
                a = a.divide(BigInteger.valueOf(b));
            }
            for (int j = n - 1; j >= 0; -- j) {
                int d = buffer.get(j);
                out.printf("%c", d < 10? '0' + d: 'A' + d - 10);
            }
View Full Code Here

class Solver {
    BigInteger choose(int n, int k) {
        BigInteger result = BigInteger.ONE;
        for (int i = 0; i < k; ++ i) {
            result = result.multiply(BigInteger.valueOf(n - i));
            result = result.divide(BigInteger.valueOf(i + 1));
        }
        return result;
    }

    BigInteger square(BigInteger x) {
View Full Code Here

        for (int i = 1; i <= n; ++ i) {
            if (count[i] > 0) {
                result = result.add(getPower(i).multiply(BigInteger.valueOf(count[i])));
            }
        }
        out.println(result.divide(BigInteger.valueOf(n)));
        out.close();
    }
}

public class Solution {
View Full Code Here

       * correct answer eventually, but in practice this branch should almost never be entered,
       * and even then the loop should not run more than once.
       */
      do {
        approxLog10--;
        approxPow = approxPow.divide(BigInteger.TEN);
        approxCmp = approxPow.compareTo(x);
      } while (approxCmp > 0);
    } else {
      BigInteger nextPow = BigInteger.TEN.multiply(approxPow);
      int nextCmp = nextPow.compareTo(x);
View Full Code Here

            if (i != nwords - 1) {
                result.append(",");
            }

            RR = RR.divide(B);
        }
        result.append("}");

        result.append("}");
        return result.toString();
View Full Code Here

            coeffs[i] = sum.mod(BigInteger.valueOf(3)).intValue() - 1;
            if (coeffs[i] > 1)
            {
                coeffs[i] -= 3;
            }
            sum = sum.divide(BigInteger.valueOf(3));
        }
        return coeffs;
    }

    /**
 
View Full Code Here

    BigInteger m2 = new BigInteger("-2");
    BigInteger m3 = new BigInteger("-3");
    BigInteger m4 = new BigInteger("-4");
   
    harness.check(p4.divide(p2).equals(p2));
    harness.check(m4.divide(p2).equals(m2));
    harness.check(p4.divide(m2).equals(m2));
    harness.check(m4.divide(m2).equals(p2));

    harness.check(p1.divide(p2).equals(BigInteger.ZERO));
    harness.check(m1.divide(p2).equals(BigInteger.ZERO));
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.