Package java.math

Examples of java.math.BigInteger.multiply()


        {
            remainder = remainder.multiply(FOUR);
            remainder = remainder.add(BigInteger.valueOf((a.testBit(--bl) ? 2
                : 0)
                + (a.testBit(--bl) ? 1 : 0)));
            b = result.multiply(FOUR).add(ONE);
            result = result.multiply(TWO);
            if (remainder.compareTo(b) != -1)
            {
                result = result.add(ONE);
                remainder = remainder.subtract(b);
View Full Code Here


            remainder = remainder.multiply(FOUR);
            remainder = remainder.add(BigInteger.valueOf((a.testBit(--bl) ? 2
                : 0)
                + (a.testBit(--bl) ? 1 : 0)));
            b = result.multiply(FOUR).add(ONE);
            result = result.multiply(TWO);
            if (remainder.compareTo(b) != -1)
            {
                result = result.add(ONE);
                remainder = remainder.subtract(b);
            }
View Full Code Here

    public byte[] toBinary3Tight()
    {
        BigInteger sum = Constants.BIGINT_ZERO;
        for (int i = coeffs.length - 1; i >= 0; i--)
        {
            sum = sum.multiply(BigInteger.valueOf(3));
            sum = sum.add(BigInteger.valueOf(coeffs[i] + 1));
        }

        int size = (BigInteger.valueOf(3).pow(coeffs.length).bitLength() + 7) / 8;
        byte[] arr = sum.toByteArray();
View Full Code Here

        int N = coeffs.length;

        // upper bound for resultant(f, g) = ||f, 2||^deg(g) * ||g, 2||^deg(f) = squaresum(f)^(N/2) * 2^(deg(f)/2) because g(x)=x^N-1
        // see http://jondalon.mathematik.uni-osnabrueck.de/staff/phpages/brunsw/CompAlg.pdf chapter 3
        BigInteger max = squareSum().pow((N + 1) / 2);
        max = max.multiply(BigInteger.valueOf(2).pow((degree() + 1) / 2));
        BigInteger max2 = max.multiply(BigInteger.valueOf(2));

        // compute resultants modulo prime numbers
        BigInteger prime = BigInteger.valueOf(10000);
        BigInteger pProd = Constants.BIGINT_ONE;
View Full Code Here

            {
                prime = prime.nextProbablePrime();
            }
            Future<ModularResultant> task = executor.submit(new ModResultantTask(prime.intValue()));
            resultantTasks.add(task);
            pProd = pProd.multiply(prime);
        }

        // Combine modular resultants to obtain the resultant.
        // For efficiency, first combine all pairs of small resultants to bigger resultants,
        // then combine pairs of those, etc. until only one is left.
View Full Code Here

        if (factorial == null)
        {
            factorial = BigInteger.ONE;
            for (int i = n; i > 1; i--)
            {
                factorial = factorial.multiply(BigInteger.valueOf(i));
            }
            if (n < CACHE_SIZE) // Cache value.
            {
                BIG_FACTORIALS.putIfAbsent(n, factorial);
            }
View Full Code Here

            }
            inverses[i] = inverse(products[i], modulus[i]);
        }
        BigInteger base = BigInteger.ONE;
        for (int i = 1; i < n; ++ i) {
            base = base.multiply(BigInteger.valueOf(b));
        }
        ArrayList <BigInteger> result = new ArrayList <BigInteger>();
        for (int mask = 0; mask < (1 << m); ++ mask) {
            BigInteger sum = BigInteger.ZERO;           
            for (int i = 0; i < m; ++ i) {
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;
    }
View Full Code Here

    }

    BigInteger factorial(int n) {
        BigInteger result = BigInteger.ONE;
        for (int i = 1; i <= n; ++ i) {
            result = result.multiply(BigInteger.valueOf(i));
        }
        return result;
    }

    BigInteger solve(int n, int k) {
View Full Code Here

            derangement[i] = BigInteger.valueOf(i - 1).multiply(derangement[i - 1].add(derangement[i - 2]));
        }
        BigInteger ways = derangement[n - k].multiply(binom[n][k]);
        BigInteger total = BigInteger.ONE;
        for (int i = 1; i <= n; ++ i) {
            total = total.multiply(BigInteger.valueOf(i));
        }
        if (true) {
            BigInteger d = ways.gcd(total);
            ways = ways.divide(d);
            total = total.divide(d);
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.