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 Go (judge verdict: Time Limit Exceeded)

package main

import (
	"fmt"
	"math"
)

func main() {
	var num int
	fmt.Scan(&num)
	fmt.Printf("%d:", num)
	res := factorize(num)
	for i := 0; i < len(res); i++ {
		fmt.Printf(" %d", res[i])
	}
	fmt.Println()
}

func factorize(num int) []int {
	nextprime := primegen()
	res := make([]int, 1)
	for i := nextprime(); i <= num; i = nextprime() {
		if num%i == 0 {
			res[0] = i
			res = append(res, factorize(num/i)...)
			return res
		}
	}
	return nil
}

func isPrime(num int) bool {
	if num < 2 {
		return false
	}
	if num == 2 {
		return true
	}
	if num%2 == 0 {
		return false
	}
	sqrt := int(math.Sqrt(float64(num)))
	for i := 3; i <= sqrt; i++ {
		if num%i == 0 {
			return false
		}
	}
	return true
}

func primegen() func() int {
	i := 0
	return func() int {
		i++
		for !isPrime(i) {
			i++
		}
		return i
	}
}