#include<stdio.h>
#define num 10000000
int a[10000009]={0};
void sieve()
{
int i,j;
for(i=2;i<=3164;i++) //loop till sqrt of largest number 10^7
{
if(a[i]==0) // all primes are marked 0
{
for(j=i*i;j<=num;j+=i)
{
if(a[j]==0)
a[j]=i; // if i is prime then all it's multiples pos have value of i
}
}
}
return; // a[] is storing each nummber's smallest prime number which can divide it
}
int main()
{
int n=0;
a[1]=0;
sieve();
while(scanf("%d",&n)!=EOF)
{
printf("1");
if(n==1)
{
printf("\n");
continue;
}
int k=n;
while(a[k]!=0) // while it doesnt reach a prime number
{
printf(" x %d",a[k]);
k/=a[k];
}
printf(" x %d",k); //print that prime number
printf("\n");
}
return 0;
}
hello, this is a code to print the factorization of a number upto 10^7 efficiently than brute force(much).So i want to optimize it more further. any one can make it more optimize so as to run it in better time ? thanks