require 'prime' x = gets.to_i if Prime.prime?(x) puts x exit 0 end d = [1] Prime.each(Math.sqrt(x)) do |i| next if 0 != x % i n = x while 0 == n % i n /= i if d.include?(i) d.delete(i) next end d << i end end puts d.inject(:*)