@@ -827,8 +827,8 @@ struct Factorizer {
827827 const BigInteger bIndex = dis (gen) % threadRange;
828828 const BigInteger halfBIndex = threadOffset + (bIndex >> 1U ) + 1U ;
829829 const BigInteger bNum = (bIndex & 1U ) ? halfBIndex : (batchTotal - halfBIndex);
830- BigInteger n = forwardFn ((bNum * wheelEntryCount) + (dis (gen) % wheelEntryCount));
831- const std::vector<size_t > pfv = factorizationVector (& n);
830+ const BigInteger n = forwardFn ((bNum * wheelEntryCount) + (dis (gen) % wheelEntryCount));
831+ const std::vector<size_t > pfv = factorizationVector (n);
832832 if (!pfv.size ()) {
833833 continue ;
834834 }
@@ -837,6 +837,20 @@ struct Factorizer {
837837 fv[pi] += pfv[pi];
838838 }
839839 }
840+ // We actually want not just a smooth number,
841+ // but a smooth perfect square.
842+ for (size_t pi = 0U ; pi < primes.size (); ++pi) {
843+ size_t & vp = fv[pi];
844+ if (vp & 1U ) {
845+ // If the prime factor component parity is odd,
846+ // multiply by the prime once to make it even.
847+ perfectSquare *= primes[pi];
848+ ++vp;
849+ }
850+ // The parity is necessarily even in this factor, by now.
851+ // Divide by 2 to get the count of square prime factors.
852+ vp >>= 1U ;
853+ }
840854
841855 const size_t batchLimit = smoothBatchLimit * (1ULL << batchPower);
842856 batchPower = (batchPower + 1U ) % batchSizeVariance;
@@ -957,8 +971,7 @@ struct Factorizer {
957971 }
958972
959973 // Compute the prime factorization.
960- std::vector<size_t > factorizationVector (BigInteger* numPtr) {
961- BigInteger& num = *numPtr;
974+ std::vector<size_t > factorizationVector (BigInteger num) {
962975 std::vector<size_t > vec (primes.size (), 0 );
963976 while (true ) {
964977 // Proceed in steps of the GCD with the smooth prime wheel radius.
@@ -990,20 +1003,6 @@ struct Factorizer {
9901003 // because it is not smooth.
9911004 return std::vector<size_t >();
9921005 }
993- // We actually want not just a smooth number,
994- // but a smooth perfect square.
995- for (size_t pi = 0U ; pi < primes.size (); ++pi) {
996- size_t & vp = vec[pi];
997- if (vp & 1U ) {
998- // If the prime factor component parity is odd,
999- // multiply by the prime once to make it even.
1000- num *= primes[pi];
1001- ++vp;
1002- }
1003- // The parity is necessarily even in this factor, by now.
1004- // Divide by 2 to get the count of square prime factors.
1005- vp >>= 1U ;
1006- }
10071006
10081007 // This number is necessarily a smooth perfect square.
10091008 return vec;
0 commit comments