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)

#include <stdio.h>
#include <math.h>

int sosu[10000] = {0};
//int factors[31] = {0};

int getSosuu(int N) {
	int i,j;
	int count_prime = 1;
	int flag;

	sosu[0] = 2;
	for (i = 2; i<=N;++i) {
		flag = 0;
		for ( j = 0; sosu[j] != 0; ++j) {
			if (i%sosu[j] == 0) {
				flag = 1;
				break;
			}
		}

		if (flag == 0) {
			sosu[count_prime] = i;
			count_prime++;
		}
	}
	return 0;
}

int add(int factor, int factors[]) {
	int i;
	for (i = 0; i < 31; ++i) {
		if (factors[i] == 0) {
			factors[i] = factor;
			break;
		}
	}
	return 0;
}

int factor(int N, int factors[]) {
	int i;
	for (i = 0; sosu[i] != 0; ++i) {
		if (N % sosu[i] == 0) {
			add(sosu[i], factors);
			factor(N / sosu[i], factors);
			break;
		}
	}
	return 0;
}

int main()
{
	int n;
	int i;
//	int n_root;
	int factors[31] = {0};
	getSosuu(100000);
	scanf("%d", &n);
//	n_root = (int)sqrt((double)n);
	factor(n, factors);
	printf("%d:", n);
	for (i = 0; factors[i] != 0; ++i) {
		printf(" %d", factors[i]);
	}

	if (factors[0] == 0) {
		printf(" %d", n);
	}
	printf("\n");
	return 0;
}