Created
August 29, 2018 02:24
-
-
Save juanfurattini/026c8708b24a49e261d84a1f411185b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'prime' | |
def solution(n) | |
primes, powers = n.prime_division.transpose | |
exponents = powers.map { |i| (0..i).to_a } | |
divisors = exponents.shift.product(*exponents).map do |powers| | |
primes.zip(powers).map { |prime, power| prime ** power }.inject(:*) | |
end | |
result = divisors.sort.map { |div| [div, n / div] } | |
return 0 if result.nil? | |
result.flatten.uniq.size | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment