5 # Returns a Hash of prime factors of self.
6 # Each key is a prime factor of self, and factors[i] is the power of that prime factor
7 # For example 45.prime_factors # => {3 => 2, 5 => 1}
8 # or, 45 = 3 ** 2 * 5 ** 1
10 primes
= Primes
.instance
16 factors
[primes
[i
]] += 1
25 def number_of_divisors
26 factors
= prime_factors
27 factors
.keys
.reduce(1) {|a
, factor
| a
*= factors
[factor
] + 1}
31 factors
= prime_factors
33 (0..factors
[f
]).map
{|a
| f
** a
}.reduce(:+)
37 def sum_of_proper_divisors
38 sum_of_divisors
- self
42 sum_of_proper_divisors
== self
46 sum_of_proper_divisors
> self
50 sum_of_proper_divisors
< self