@@ -102,21 +102,20 @@ public void searchFactors(FactorArguments args, FactorResult result) {
102102 int p_i ;
103103 for (int i =1 ; (p_i =SMALL_PRIMES .getPrime (i ))<=pLimit ; i ++) {
104104 BigInteger p_i_big = BigInteger .valueOf (p_i );
105- BigInteger [] div = N .divideAndRemainder (p_i_big );
106- if (div [1 ].equals (I_0 )) {
107- // p_i divides N at least once
108- do {
109- addToMap (p_i_big , Nexp , primeFactors );
110- N = div [0 ];
111- div = N .divideAndRemainder (p_i_big );
112- } while (div [1 ].equals (I_0 ));
113-
114- // At least one division has occurred; check if we are done.
115- // Probably the check could be improved but it wont make much difference because the divisions are much more expensive.
105+ BigInteger [] div ;
106+ int exp = 0 ;
107+ while ((div = N .divideAndRemainder (p_i_big ))[1 ].equals (I_0 )) {
108+ N = div [0 ];
109+ exp ++;
110+ }
111+ if (exp > 0 ) {
112+ // At least one exact division has occurred; add to results
113+ addToMap (p_i_big , exp *Nexp , primeFactors );
116114 if (N .bitLength () < 63 ) {
115+ // Check if we are done
117116 long p_i_square = p_i *(long )p_i ;
118117 if (p_i_square > N .longValue ()) {
119- // LOG.debug("N=" + N + " < p^2=" + p_i_square);
118+ if ( DEBUG ) LOG .debug ("N=" + N + " < p^2=" + p_i_square );
120119 // the remaining N is 1 or prime
121120 if (N .compareTo (I_1 )>0 ) addToMap (N , Nexp , primeFactors );
122121 result .smallestPossibleFactor = p_i ; // may be helpful in following factor algorithms
0 commit comments