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

#include<stdio.h>
long long int prime[5000],arr[20000000];
long long int size=1,size2=1;

void primenum(int n)
{
    int i,j,k,sqr;
    for(i=1; i<=n; i++)
        arr[i]=1;
    for(i=4; i<=n; i+=2)
        arr[i]=0;
    for(i=3; i*i<=n; i+=2)
    {
        for(j=2; i*j<=n; j++)
        {
            if(arr[i*j]==1)
                arr[i*j]=0;
        }
    }
    for(i=1; i<=n; i++)
    {
        if(arr[i]==1)
        {
            prime[size]=i;
            size++;
        }
    }
    primefactorization(n);

    return;
}
void primefactorization(int n)
{
    int sqr,i,j;
    sqr=sqrt(n);

    for(i=2;prime[i]<=sqr;i++)
    {
        while(n%prime[i]==0)
        {
            n=n/prime[i];
            printf(" %lld",prime[i]);
            size2++;
        }
    }
    if(n>1)
    {
       printf(" %lld",n);
    }

return;
}

main()
{
  long long  int i,n;
    scanf("%lld",&n);

    printf("%lld:",n);
     primenum(n);
    printf("\n");
    return 0;
}