public int trialDivide(BigInteger n) {
            BigInteger m = n;
            BigInteger p = TWO;

            while (m.compareTo(BigInteger.ONE) != 0) {
                if (m.isProbablePrime(10))
                    p = m;

                if (limit != null && !limit.equals(BigInteger.ZERO) && p.compareTo(limit) > 0)
                    p = m;

                if (isDivisible(m, p)) {
                    int mul = 0;
                    do {
                        m = m.divide(p);
                        mul++;
                    } while (isDivisible(m, p));

                    if (fun(p, mul) != 0)
                        return 1;
                }
                p = p.nextProbablePrime();
            }

            return 0;
        }