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.Linq;

static class Prime {
    public static List<int> Sieve(int n) {
        var tab = new bool[n+1];
        var ps = new List<int>();
        if (n >= 2) ps.Add(2);
        for (int i = 3; i <= n; i += 2) {
            if (!tab[i]) { // i is prime
                ps.Add(i);
                for (int j = i+i; j <= n; j += i) {
                    tab[j] = true;
                }
            }
        }
        return ps;
    }
}

class Program {
    static string ReadLine() { return Console.ReadLine(); }
    static int ReadInt() { return int.Parse(ReadLine()); }
    static int[] ReadInts() { return ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return ReadLine().Split(); }

    static List<int> Factor(int n, List<int> primes) {
        var xs = new List<int>();
        foreach (int p in primes) {
            if (p * p > n) break;
            while (n % p == 0) {
                xs.Add(p);
                n /= p;
            }
        }
        if (n > 1) xs.Add(n);
        return xs;
    }

    static void Main() {
        int n = ReadInt();
        var primes = Prime.Sieve((int)Math.Sqrt(1e9));
        var xs = Factor(n, primes);
        Console.Write("{0}:", n);
        foreach (var x in xs)
            Console.Write(" {0}", x);
        Console.WriteLine();
    }
}