I got TLE twice. But I don't see how I can optimize my solution. Could you please help me with this. Here is my code (w/o includes and other formal things):

Code: Select all

```
#define Fori(i,a,b) for(int i = a; i < (int)b; ++i)
#define M 2000001
int a[M];
int b[M];
int f(int x)
{
int res=0;
int xx=x;
while(!(xx%2))
{
++res;
xx/=2;
}
int lim=(int)sqrt((double)x)+1;
for(int f=3;f<=lim && xx>1;f+=2)
{
while(!(xx%f))
{
++res;
xx/=f;
}
}
if(xx!=1) ++res;
return res;
}
bool cmp(int x,int y)
{
if(b[x]!=b[y])
return (b[x]<b[y]);
else
return x<y;
}
int main ()
{
a[0]=0;
Fori(i,1,M) a[i]=i;
b[0]=0;
Fori(i,1,M) b[i]=f(i);
int n;
int c=1;
sort(a,a+M,cmp);
while(cin >> n)
{
if(n==0)break;
printf("Case %d: %d\n",c,a[n]);
c++;
}
return 0;
}
```

**Title editied by Moderator**