prime_division

prime_division(value, generator= Prime::Generator23.new)
Instance Public methods

Returns the factorization of value.

Parameters

value

An arbitrary integer.

generator

Optional. A pseudo-prime generator. generator.succ must return the next pseudo-prime number in the ascendent order. It must generate all prime numbers, but may generate non prime numbers.

Exceptions

ZeroDivisionError

when value is zero.

Example

For an arbitrary integer:

n = p_1**e_1 * p_2**e_2 * .... * p_n**e_n,

#prime_division(n) returns:

[[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]].

Prime.prime_division(12) #=> [[2,2], [3,1]]
doc_ruby_on_rails
2015-04-28 14:51:10
Comments
Leave a Comment

Please login to continue.