Skip to content

Commit a39b9cc

Browse files
Fix exit condition after G.E.
1 parent 4e5b829 commit a39b9cc

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

FindAFactor/_find_a_factor.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,8 @@ struct Factorizer {
779779
}
780780
}
781781

782+
void resetIsIncomplete() { isIncomplete = true; }
783+
782784
BigInteger getNextAltBatch() {
783785
std::lock_guard<std::mutex> lock(batchMutex);
784786

@@ -941,7 +943,7 @@ struct Factorizer {
941943
auto ikit = smoothNumberKeys.begin();
942944
auto ivit = smoothNumberValues.begin();
943945
BigInteger result = 1U;
944-
for (size_t i = 0U; i < smoothNumberKeys.size(); ++i) {
946+
for (size_t i = 0U; isIncomplete && (i < smoothNumberKeys.size()); ++i) {
945947
dispatch.dispatch([this, i, ikit, ivit, &result]() -> bool {
946948
auto jkit = ikit;
947949
auto jvit = ivit;
@@ -958,6 +960,7 @@ struct Factorizer {
958960
// Check congruence of squares
959961
BigInteger factor = gcd(this->toFactor, x + y);
960962
if ((factor != 1U) && (factor != this->toFactor)) {
963+
isIncomplete = false;
961964
std::lock_guard<std::mutex> lock(this->batchMutex);
962965
result = factor;
963966

@@ -968,6 +971,7 @@ struct Factorizer {
968971
// Try x - y as well
969972
factor = gcd(this->toFactor, x - y);
970973
if ((factor != 1U) && (factor != this->toFactor)) {
974+
isIncomplete = false;
971975
std::lock_guard<std::mutex> lock(this->batchMutex);
972976
result = factor;
973977

@@ -1224,6 +1228,7 @@ std::string find_a_factor(std::string toFactorStr, size_t method, size_t nodeCou
12241228
for (unsigned cpu = 0U; cpu < futures.size(); ++cpu) {
12251229
futures[cpu].get();
12261230
}
1231+
worker.resetIsIncomplete();
12271232

12281233
return boost::lexical_cast<std::string>(worker.solveForFactor());
12291234
}

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 = "5.1.0"
11+
version = "5.0.5"
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='5.1.0',
43+
version='5.0.5',
4444
author='Dan Strano',
4545
author_email='stranoj@gmail.com',
4646
description='Find any nontrivial factor of a number',

0 commit comments

Comments
 (0)