Problem:
Prime Factorization

Factorize a given integer n.

Input

n

An integer n is given in a line.

Output

Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor.

Constraints

2 ≤ n ≤ 109

Sample Input 1

12

Sample Output 1

12: 2 2 3

Sample Input 2

126

Sample Output 2

126: 2 3 3 7

Solution in Ruby (judge verdict: Wrong Answer)

def is_prime?(num)
    $primes = []
    return true if num == 2
    return false if num % 2 == 0
    $primes.each do |n|
        return false if num % n == 0
    end
    $primes << num
    return true
end

n = gets.chomp.to_i
nn = n
sub_n = 2
prime_factors = []
while n > 1
	if n % sub_n == 0
      n /= sub_n
	  prime_factors << sub_n
	  next
	else
      break if sub_n * sub_n > n
      if sub_n == 2
        sub_n += 1
      else
        sub_n += 2
        while !is_prime?(sub_n)
          sub_n += 2
        end
      end
	end
end																				 
str = "#{nn}:"
prime_factors.each do |k|
	str += " #{k}"
end
if n == nn
  str << " #{nn}"
end
puts str