Skip to content

Instantly share code, notes, and snippets.

@yuuki
Created July 27, 2012 18:17
Show Gist options
  • Save yuuki/3189532 to your computer and use it in GitHub Desktop.
Save yuuki/3189532 to your computer and use it in GitHub Desktop.
#!/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