diff options
author | lloyd <[email protected]> | 2006-07-16 09:48:55 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-07-16 09:48:55 +0000 |
commit | 688e9b460061951aaf22d6165e7c03ef5b93307d (patch) | |
tree | 783cf8ae79b695d675c9db9c09447cf316d29d7f | |
parent | fc8fa48714eaf79bf9b861981066b7a6c74a702f (diff) |
Move the declaration of a_factor outside the loop, and use a do loop
instead of a while loop so it doesn't have to be initialized each time
through.
-rw-r--r-- | doc/examples/factor.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/doc/examples/factor.cpp b/doc/examples/factor.cpp index b8e02e19f..93a7a0e9e 100644 --- a/doc/examples/factor.cpp +++ b/doc/examples/factor.cpp @@ -29,11 +29,12 @@ BigInt rho(const BigInt& n) i++; x = mod_n.multiply((x + 1), x); + d = gcd(y - x, n); if(d != 1 && d != n) return d; - if(i == 65536) // fail + if(i == 65536) // bail break; if(i == k) @@ -84,7 +85,7 @@ std::vector<BigInt> remove_small_factors(BigInt& n) std::vector<BigInt> factorize(const BigInt& n_in) { - BigInt n = n_in; + BigInt n = n_in, a_factor = 0; std::vector<BigInt> factors = remove_small_factors(n); while(n != 1) @@ -95,9 +96,9 @@ std::vector<BigInt> factorize(const BigInt& n_in) break; } - BigInt a_factor = 0; - while(a_factor == 0) + do a_factor = rho(n); + while(a_factor == 0); factors.push_back(a_factor); n /= a_factor; |