I am getting TLE pease help

i am getting tle on this problem-SPOJ.com - Problem FACTCG2
my code-
#include <bits/stdc++.h>
using namespace std;
#define n 10000001
int spf[n];
void primenumbers(int a){

	while(a!=1){
	
	cout<<spf[a];
	a=a/spf[a];
	if(a!=1)
	 cout<<" x ";
}

}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
for(int i=2;i<n;i++){
spf[i]=i;
}
for(int i=2;ii<n;i++){
if(spf[i]==i){
for(int j=i
i;j<n;j+=i){
if(spf[j]==j)
spf[j]=i;

		}
	}
}

int a;

while(cin>>a){
 
   if(a==1){
       cout<<1;
   }
   else{
       cout<<1<<" x ";primenumbers(a);
   }cout<<endl;
}



return 0;

}
please tell me how can ui solve this