Module: FasterPrime
- Extended by:
- Core
- Includes:
- Core
- Defined in:
- lib/faster_prime/base.rb,
lib/faster_prime/sieve.rb,
lib/faster_prime/utils.rb,
lib/faster_prime/version.rb,
lib/faster_prime/primality_test.rb,
lib/faster_prime/prime_factorization.rb
Defined Under Namespace
Modules: Core, PollardRho, PrimalityTest, PrimeFactorization, Sieve, Utils Classes: Failed, MPQS
Constant Summary collapse
- SMALL_PRIMES =
[]
- SMALL_PRIME_TABLE =
[]
- VERSION =
"1.0.2"
Class Method Summary collapse
Methods included from Core
each, int_from_prime_division, prime?, prime_division
Class Method Details
.instance ⇒ Object
38 39 40 |
# File 'lib/faster_prime/base.rb', line 38 def self.instance self end |
.setup_table(n) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/faster_prime/utils.rb', line 5 def self.setup_table(n) n = (n + 59) / 60 * 60 SMALL_PRIMES.clear << 2 n /= 2 SMALL_PRIME_TABLE.replace([true] * n) i = 1 while i < n if SMALL_PRIME_TABLE[i] SMALL_PRIMES << j = i * 2 + 1 k = i + j while k < n SMALL_PRIME_TABLE[k] = false k += j end end i += 1 end end |