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 C# (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Text;


namespace NTL1_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var sb = new StringBuilder();
            int n = int.Parse(Console.ReadLine());
            var P = new List<int>();
            eratos(P, (int)Math.Sqrt(n));

            sb.Append(n + ":");
            int i = 0;
            while (true)
            {
                if (n % P[i] != 0)
                {
                    i++;
                }
                else
                {
                    n /= P[i];
                    sb.Append(" " + P[i]);
                }
                if (i == P.Count)
                {
                    sb.Append(" " + n);
                    break;
                }
                if (n == 1)
                {
                    break;
                }

            }

            Console.WriteLine(sb);
        }
        //2???n?????§????´???°????????????(n>=2)
        static void eratos(List<int> P, int n)
        {
            var a = new bool[n + 1];
            a[0] = a[1] = true;
            int i;
            for (i = 2; i * i <= n; i++)
            {
                if (!a[i])
                {
                    P.Add(i);
                    int j = i << 1;
                    while (j <= n)
                    {
                        a[j] = true;
                        j = j + i;
                    }
                }
            }
            for (; i <= n; i++) if (!a[i]) P.Add(i);
        }
        
	}
     
    
}