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: Accepted)

def prime_factorization(num)
  prime_factor = 2
  arr = []

  until num == 1
    if num % prime_factor == 0
      arr << prime_factor

      num /= prime_factor
    else
      if prime?(num)
        arr << num
        break
      end

      prime_factor += prime_factor == 2 ? 1 : 2
    end
  end

  arr
end

def prime?(i)
  num = 3

  while num <= Math.sqrt(i)
    return false if i % num == 0

    num += 2
  end

  true
end

n = gets.to_i

puts "#{n}: #{prime_factorization(n).join(' ')}"