Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Prime#int_from_prime_division

int_from_prime_division(pd)

Re-composes a prime factorization and returns the product.

For the decomposition:

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

it returns:

p_1**e_1 * p_2**e_2 * ... * p_n**e_n.

Parameters

pd

Array of pairs of integers. Each pair consists of a prime number – a prime factor – and a natural number – its exponent (multiplicity).

Example

Example
Prime.int_from_prime_division([[3, 2], [5, 1]])  #=> 45
3**2 * 5                                         #=> 45