Flowdock
method

prime_division

Importance_2
Ruby latest stable (v1_9_3_392) - 0 notes - Class: Prime
prime_division(value, generator= Prime::Generator23.new) public

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]]
Show source
Register or log in to add new notes.