# Square free Integer

I am an amateur programmer and I tried coding this problem using the TurboC++ IDE (though my code is in C), but the site's compiler throws a "TIME LIMIT EXCEEDED" error. How can I optimize my code further?

#include<stdio.h>
#include<math.h>
int main()
{
long int n,j,k,sqt,tot,t,i,c;

scanf("%ld",&t);
for(i=0;i<t;i++)
{
scanf("%ld",&n); tot=n;
for(k=1;;k++)
{c=0;
for(j=k;j>=2;j--)
{
if((k%j)==0)
{ if(((long)sqrt(j)*(long)sqrt(j)!=j))
{c=0;}
else {c++;break; }
}
}
if(c==0)
{tot--;}
if(tot==0)  {printf("%ld\n",k);break;}
}
}

return 0;
}


Please do tell me if the code is wrong.

• Have you tried your code on some sample inputs? Does it seem to work? – svick Jun 6 '13 at 13:54
• @svick yes it does work for all those that i tried – ragsvds Jun 6 '13 at 14:17

1