Skip to content

Instantly share code, notes, and snippets.

@juanfurattini
Created August 29, 2018 02:24
Show Gist options
  • Save juanfurattini/026c8708b24a49e261d84a1f411185b6 to your computer and use it in GitHub Desktop.
Save juanfurattini/026c8708b24a49e261d84a1f411185b6 to your computer and use it in GitHub Desktop.
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