FindAFactor 3.6.7__tar.gz → 3.6.9__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -41,12 +41,7 @@
41
41
  #include "dispatchqueue.hpp"
42
42
 
43
43
  #include <algorithm>
44
- #include <chrono>
45
- #include <cmath>
46
- #include <float.h>
47
- #include <fstream>
48
44
  #include <future>
49
- #include <iomanip>
50
45
  #include <iostream>
51
46
  #include <map>
52
47
  #include <memory>
@@ -54,7 +49,6 @@
54
49
  #include <random>
55
50
  #include <stdlib.h>
56
51
  #include <string>
57
- #include <time.h>
58
52
 
59
53
  #include <boost/dynamic_bitset.hpp>
60
54
  #include <boost/multiprecision/cpp_int.hpp>
@@ -189,7 +183,7 @@ inline size_t backward3(const size_t &n) { return (size_t)((~(~n | 1U)) / 3U) +
189
183
  constexpr unsigned char wheel5[8U] = {1U, 7U, 11U, 13U, 17U, 19U, 23U, 29U};
190
184
 
191
185
  // Make this NOT a multiple of 2, 3, or 5.
192
- size_t forward5(const size_t &p) { return wheel5[p % 8U] + (p / 8U) * 30U; }
186
+ size_t forward5(const size_t &p) { return wheel5[p & 7U] + (p >> 3U) * 30U; }
193
187
 
194
188
  size_t backward5(const size_t &n) { return std::distance(wheel5, std::lower_bound(wheel5, wheel5 + 8U, (size_t)(n % 30U))) + 8U * (size_t)(n / 30U) + 1U; }
195
189
 
@@ -486,7 +480,7 @@ inline BigInteger _forward3(const BigInteger &p) { return (p << 1U) + (~(~p | 1U
486
480
 
487
481
  inline BigInteger _backward3(const BigInteger &n) { return ((~(~n | 1U)) / 3U) + 1U; }
488
482
 
489
- BigInteger _forward5(const BigInteger &p) { return wheel5[(size_t)(p % 8U)] + (p / 8U) * 30U; }
483
+ BigInteger _forward5(const BigInteger &p) { return wheel5[(size_t)(p & 7U)] + (p >> 3U) * 30U; }
490
484
 
491
485
  BigInteger _backward5(const BigInteger &n) { return std::distance(wheel5, std::lower_bound(wheel5, wheel5 + 8U, (size_t)(n % 30U))) + 8U * (n / 30U) + 1U; }
492
486
 
@@ -769,7 +763,6 @@ struct Factorizer {
769
763
  size_t rowOffset;
770
764
  bool isIncomplete;
771
765
  std::vector<size_t> primes;
772
- std::vector<size_t> sqrPrimes;
773
766
  ForwardFn forwardFn;
774
767
  std::vector<BigInteger> smoothNumberKeys;
775
768
  std::vector<boost::dynamic_bitset<size_t>> smoothNumberValues;
@@ -782,7 +775,6 @@ struct Factorizer {
782
775
  for (size_t i = 0U; i < primes.size(); ++i) {
783
776
  const size_t& p = primes[i];
784
777
  wheelRadius *= p;
785
- sqrPrimes.push_back(p * p);
786
778
  smoothNumberKeys.push_back(p);
787
779
  smoothNumberValues.emplace_back(primes.size(), 0);
788
780
  smoothNumberValues.back()[i] = true;
@@ -867,7 +859,7 @@ struct Factorizer {
867
859
  continue;
868
860
  }
869
861
  factor /= p;
870
- vec[pi] = !vec[pi];
862
+ vec.flip(pi);
871
863
  if (factor == 1U) {
872
864
  break;
873
865
  }
@@ -875,7 +867,7 @@ struct Factorizer {
875
867
  if (num == 1U) {
876
868
  return vec;
877
869
  }
878
- };
870
+ }
879
871
  if (num != 1U) {
880
872
  return boost::dynamic_bitset<size_t>();
881
873
  }
@@ -995,26 +987,24 @@ struct Factorizer {
995
987
  }
996
988
 
997
989
  BigInteger checkPerfectSquare(BigInteger perfectSquare) {
998
- while (perfectSquare < toFactorSqr) {
999
- // Compute x and y
1000
- const BigInteger x = perfectSquare % toFactor;
1001
- const BigInteger y = modExp(x, toFactor >> 1U, toFactor);
1002
-
1003
- // Check congruence of squares
1004
- BigInteger factor = gcd(toFactor, x + y);
1005
- if ((factor != 1U) && (factor != toFactor)) {
1006
- return factor;
1007
- }
990
+ // Compute x and y
991
+ const BigInteger x = perfectSquare % toFactor;
992
+ const BigInteger y = modExp(x, toFactor >> 1U, toFactor);
993
+
994
+ // Check congruence of squares
995
+ BigInteger factor = gcd(toFactor, x + y);
996
+ if ((factor != 1U) && (factor != toFactor)) {
997
+ return factor;
998
+ }
1008
999
 
1009
- if (x != y) {
1010
- // Try x - y as well
1011
- factor = gcd(toFactor, x - y);
1012
- if ((factor != 1U) && (factor != toFactor)) {
1013
- return factor;
1014
- }
1015
- }
1000
+ if (x == y) {
1001
+ return 1U;
1002
+ }
1016
1003
 
1017
- perfectSquare *= sqrPrimes[dis(gen)];
1004
+ // Try x - y as well
1005
+ factor = gcd(toFactor, x - y);
1006
+ if ((factor != 1U) && (factor != toFactor)) {
1007
+ return factor;
1018
1008
  }
1019
1009
 
1020
1010
  return 1U;
@@ -1198,10 +1188,11 @@ std::string find_a_factor(const std::string &toFactorStr, const bool &isConOfSqr
1198
1188
  const size_t maxPrimeCount = std::min(primes.size(), smoothPrimeCount);
1199
1189
  std::vector<size_t> smoothPrimes;
1200
1190
  for (size_t primeId = 0U; (primeId < primes.size()) && (smoothPrimes.size() < maxPrimeCount); ++primeId) {
1201
- const size_t residue = (size_t)(toFactor % primes[primeId]);
1191
+ const size_t p = primes[primeId];
1192
+ const size_t residue = (size_t)(toFactor % p);
1202
1193
  const size_t sr = _sqrt(residue);
1203
1194
  if ((sr * sr) == residue) {
1204
- smoothPrimes.push_back(primes[primeId]);
1195
+ smoothPrimes.push_back(p);
1205
1196
  }
1206
1197
  }
1207
1198
  if (smoothPrimes.size() < maxPrimeCount) {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: FindAFactor
3
- Version: 3.6.7
3
+ Version: 3.6.9
4
4
  Summary: Find any nontrivial factor of a number
5
5
  Home-page: https://github.com/vm6502q/FindAFactor
6
6
  Author: Dan Strano
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: FindAFactor
3
- Version: 3.6.7
3
+ Version: 3.6.9
4
4
  Summary: Find any nontrivial factor of a number
5
5
  Home-page: https://github.com/vm6502q/FindAFactor
6
6
  Author: Dan Strano
@@ -26,7 +26,7 @@ ext_modules = [
26
26
 
27
27
  setup(
28
28
  name='FindAFactor',
29
- version='3.6.7',
29
+ version='3.6.9',
30
30
  author='Dan Strano',
31
31
  author_email='dan@unitary.fund',
32
32
  description='Find any nontrivial factor of a number',
File without changes
File without changes
File without changes