Skip to content

Commit fcd134b

Browse files
Better smooth seeding
1 parent 38da903 commit fcd134b

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

FindAFactor/_find_a_factor.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -827,11 +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-
const BigInteger n = forwardFn((bNum * wheelEntryCount) + (dis(gen) % wheelEntryCount));
831-
const std::vector<size_t> pfv = factorizationVector(n);
832-
if (!pfv.size()) {
833-
continue;
834-
}
830+
BigInteger n = forwardFn((bNum * wheelEntryCount) + (dis(gen) % wheelEntryCount));
831+
const std::vector<size_t> pfv = factorizationVector(&n);
835832
perfectSquare *= n;
836833
for (size_t pi = 0U; pi < primes.size(); ++pi) {
837834
fv[pi] += pfv[pi];
@@ -971,7 +968,8 @@ struct Factorizer {
971968
}
972969

973970
// Compute the prime factorization.
974-
std::vector<size_t> factorizationVector(BigInteger num) {
971+
std::vector<size_t> factorizationVector(BigInteger* numPtr) {
972+
BigInteger num = *numPtr;
975973
std::vector<size_t> vec(primes.size(), 0);
976974
while (true) {
977975
// Proceed in steps of the GCD with the smooth prime wheel radius.
@@ -999,9 +997,9 @@ struct Factorizer {
999997
}
1000998
}
1001999
if (num != 1U) {
1002-
// The number was not fully factored,
1003-
// because it is not smooth.
1004-
return std::vector<size_t>();
1000+
// The number was not fully factored, because it is not smooth.
1001+
// Make it smooth, by dividing out the remaining non-smooth factors!
1002+
(*numPtr) /= num;
10051003
}
10061004

10071005
// This number is necessarily a smooth perfect square.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"
88

99
[project]
1010
name = "FindAFactor"
11-
version = "4.7.10"
11+
version = "4.7.11"
1212
requires-python = ">=3.8"
1313
description = "Find any nontrivial factor of a number"
1414
readme = {file = "README.txt", content-type = "text/markdown"}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def build_extension(self, ext):
4040

4141
setup(
4242
name='FindAFactor',
43-
version='4.7.10',
43+
version='4.7.11',
4444
author='Dan Strano',
4545
author_email='stranoj@gmail.com',
4646
description='Find any nontrivial factor of a number',

0 commit comments

Comments
 (0)