TOPIC

Time limit exceeded

SHUVRA ADITYA (IIT_NSTU) (͡ ° ͜ʖ ͡ °) asked 2 years ago

here is my code!!! . .

#include<stdio.h>
int main()
{
    int i, j, k, t, n, c=0;
    int num[105]={0};
    num[0]=0;
    scanf("%d",&t);
    for(i=0; i<t; i++)
    {

        for(j=1; j<=45360 ; j++)
        {
            c=0;
            for(k=1; k<=j; k++)
            {
                if(j%k==0)
                {
                    c++;
                }
            }
            if(num[c]==0)
            {
                num[c]=j;
            }
        }
        scanf("%d",&n);
        printf("%d\n",num[n]);
    }
    return 0;
}

. . it is giving me TLE!!! I use this logic :- . .

 for(j=1; j<=45360 ; j++)
        {
            c=0;
            for(k=1; k<=j; k++)
            {
                if(j%k==0)
                {
                    c++;
                }
            }
            if(num[c]==0)
            {
                num[c]=j;
            }
        }

.

I know that, the loop is quite bit of large. If anyone can help me with more efficient algorithm, i will be gratefull!!!

This topic has not been answered yet. Be the first!

Remember not post solutions. Your post may be reviewed by our moderators.