Created
July 27, 2012 18:17
-
-
Save yuuki/3189532 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
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
require 'prime' | |
factories_count = {} | |
Prime.each(20) {|i| factories_count[i] = 0} | |
(2..20).each do |n| | |
factories_count.each_key do |k| # 素因数分解 | |
break if n < k | |
t = n # copy | |
count = 0 | |
while t >= k do | |
count += 1 if t % k == 0 | |
t /= k | |
end | |
factories_count[k] = count if factories_count[k] < count | |
end | |
end | |
puts factories_count.map { |k, v| k.to_i * v }.inject(1) { |product, i| product * i } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment