Skip to content

Commit ea582f3

Browse files
Don't reject wheel factors from residues
1 parent 9aa90dd commit ea582f3

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

FindAFactor/_find_a_factor.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ struct Factorizer {
761761
BigInteger batchOffset;
762762
BigInteger batchTotal;
763763
BigInteger wheelRadius;
764+
size_t firstGaussianElimPrimeId;
764765
size_t wheelEntryCount;
765766
size_t rowLimit;
766767
bool isIncomplete;
@@ -772,11 +773,10 @@ struct Factorizer {
772773
ForwardFn forwardFn;
773774
ForwardFn backwardFn;
774775

775-
Factorizer(const BigInteger &tf, const BigInteger &tfsqrt, const BigInteger &range, size_t nodeCount, size_t nodeId, size_t w, size_t rl, size_t bn,
776+
Factorizer(const BigInteger &tf, const BigInteger &tfsqrt, const BigInteger &range, size_t nodeCount, size_t nodeId, size_t fgepi, size_t w, size_t rl, size_t bn,
776777
const std::vector<size_t> &p, ForwardFn ffn, ForwardFn bfn)
777778
: dis(0ULL, -1ULL), toFactorSqr(tf * tf), toFactor(tf), toFactorSqrt(tfsqrt), batchRange(range), batchNumber(bn), batchOffset(nodeId * range), batchTotal(nodeCount * range),
778-
wheelRadius(1U), wheelEntryCount(w), rowLimit(rl), isIncomplete(true), primes(p),
779-
forwardFn(ffn), backwardFn(bfn)
779+
firstGaussianElimPrimeId(fgepi), wheelRadius(1U), wheelEntryCount(w), rowLimit(rl), isIncomplete(true), primes(p), forwardFn(ffn), backwardFn(bfn)
780780
{
781781
for (size_t i = 0U; i < primes.size(); ++i) {
782782
const size_t& p = primes[i];
@@ -994,7 +994,7 @@ struct Factorizer {
994994
n /= factor;
995995
// Remove smooth primes from factor.
996996
// (The GCD is necessarily smooth.)
997-
for (size_t pi = 0U; pi < primes.size(); ++pi) {
997+
for (size_t pi = firstGaussianElimPrimeId; pi < primes.size(); ++pi) {
998998
const size_t& p = primes[pi];
999999
if (factor % p) {
10001000
continue;
@@ -1136,7 +1136,7 @@ std::string find_a_factor(std::string toFactorStr, size_t method, size_t nodeCou
11361136
// Keep as many "smooth" primes as bits in number to factor.
11371137
const size_t toFactorBits = (size_t)log2(toFactor);
11381138
// Primes are only present in range above wheel factorization level
1139-
primes.erase(primes.begin(), itg);
1139+
const size_t firstGaussianElimPrimeId = std::distance(primes.begin(), itg);
11401140
std::vector<size_t> smoothPrimes;
11411141
for (size_t primeId = 0U; primeId < primes.size(); ++primeId) {
11421142
const size_t p = primes[primeId];
@@ -1173,7 +1173,7 @@ std::string find_a_factor(std::string toFactorStr, size_t method, size_t nodeCou
11731173
const BigInteger nodeRange = (((backwardFn(fullMaxBase) + nodeCount - 1U) / nodeCount) + wheelEntryCount - 1U) / wheelEntryCount;
11741174
const size_t batchStart = ((size_t)backwardFn(trialDivisionLevel)) / wheelEntryCount;
11751175
// This manages the work of all threads.
1176-
Factorizer worker(toFactor, fullMaxBase, nodeRange, nodeCount, nodeId,
1176+
Factorizer worker(toFactor, fullMaxBase, nodeRange, nodeCount, nodeId, firstGaussianElimPrimeId,
11771177
wheelEntryCount, (size_t)(gaussianEliminationRowMultiplier * smoothPrimes.size() + 0.5),
11781178
batchStart, smoothPrimes, forward(SMALLEST_WHEEL), backwardFn);
11791179
// Square of count of smooth primes, for FACTOR_FINDER batch multiplier base unit, was suggested by Lyra (OpenAI GPT)

FindAFactor/find_a_factor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ def find_a_factor(n,
1515
node_id=int(os.environ.get('FINDAFACTOR_NODE_ID')) if os.environ.get('FINDAFACTOR_NODE_ID') else 0,
1616
gear_factorization_level=int(os.environ.get('FINDAFACTOR_GEAR_FACTORIZATION_LEVEL')) if os.environ.get('FINDAFACTOR_GEAR_FACTORIZATION_LEVEL') else 11,
1717
wheel_factorization_level=int(os.environ.get('FINDAFACTOR_WHEEL_FACTORIZATION_LEVEL')) if os.environ.get('FINDAFACTOR_WHEEL_FACTORIZATION_LEVEL') else 11,
18-
sieving_bound_multiplier=float(os.environ.get('FINDAFACTOR_SIEVING_BOUND_MULTIPLIER')) if os.environ.get('FINDAFACTOR_SIEVING_BOUND_MULTIPLIER') else 1.5,
19-
smoothness_bound_multiplier=float(os.environ.get('FINDAFACTOR_SMOOTHNESS_BOUND_MULTIPLIER')) if os.environ.get('FINDAFACTOR_SMOOTHNESS_BOUND_MULTIPLIER') else 1.5,
18+
sieving_bound_multiplier=float(os.environ.get('FINDAFACTOR_SIEVING_BOUND_MULTIPLIER')) if os.environ.get('FINDAFACTOR_SIEVING_BOUND_MULTIPLIER') else 1.0,
19+
smoothness_bound_multiplier=float(os.environ.get('FINDAFACTOR_SMOOTHNESS_BOUND_MULTIPLIER')) if os.environ.get('FINDAFACTOR_SMOOTHNESS_BOUND_MULTIPLIER') else 1.0,
2020
gaussian_elimination_row_multiplier=float(os.environ.get('FINDAFACTOR_GAUSSIAN_ELIMINATION_ROW_MULTIPLIER')) if os.environ.get('FINDAFACTOR_GAUSSIAN_ELIMINATION_ROW_MULTIPLIER') else 1.5,
2121
check_small_factors=True if os.environ.get('FINDAFACTOR_CHECK_SMALL_FACTORS') else False):
2222
return int(_find_a_factor._find_a_factor(str(n),

0 commit comments

Comments
 (0)