Here is my code for spoj.pl/problems/FACTCG2/

I am getting TLE with this short method even...

#include<iostream>
#include<cstdio>
using namespace std;
void factor(int num)
{
	int i;
	printf("1");
	for(i=2;i*i<=num; )
	{
		while(num%i==0)
		{
			num/=i;
				printf(" x %d",i);
		}
		if(i==2)
			i++;
		else
			i+=2;
	}
	if(num!=1)
		printf(" x %d\n",num);
	else
		printf("\n");
}
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		factor(n);
	}
return 0;
}

if i changes with "space" in output.. it gave me TLE..

Can anyone please help me ????

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 23 14d

Want to read more? Browse other topics in C and C++ or view latest topics.