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: Time Limit Exceeded)

// 素因数分解をするプログラム

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>

int search_next_primeNumber(int num);

int main(void)
{
    int num = 0;
    int prime_factor = 2;

    scanf("%d", &num);
    printf("%d:", num);

    while( num != 1 )
    {
        if( num % prime_factor == 0 )
        {
            // 入力値を割っておく
            num /= prime_factor;
            printf(" %d", prime_factor);
        }
        else
        {
            // 素数を検索する
            prime_factor = search_next_primeNumber(prime_factor);
        }
    }

    printf("\n");

    return 0;
}

// 引数:numの次の素数を検索する関数
int search_next_primeNumber(int num)
{
    bool judge = false;

    int prime_num = num + 1;

    while( judge == false )
    {
        judge = true;

        for(int i = 2; i * i <= prime_num; i++)
        {
            if( prime_num % i == 0 )
            {
                // 素数ではない
                judge = false;
                prime_num++;
                break;
            }
        }
    }

    return prime_num;
}