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 main(input = STDIN)
  n = input.gets.to_i
  m = n
  output = ["#{n}:"]
  while m % 2 == 0
    output << 2
    m /= 2
  end
  f = 3
  while m != 1 and f ** 2 <= n
    while m % f == 0
      output << f
      m /= f
    end
    f += 2
  end
  output << n if output.size == 1
  output << m if f ** 2 > n
  puts output.join(" ")
end
main