Saturday, 26 March 2016

Solution of LIGHT OJ 1109 :: False Ordering


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
#include <math.h>

int ara[1001],k, cnt, j, tmp;

void square(int ara[])
{
    for(k=1; k<=32; k++)
        ara[k*k]=-1;
}

void devisor(int ara[])
{
    for(k=1; k<=1000; k++)
    {
        tmp = sqrt(k);
        for(j=1, cnt=0; j<=tmp; j++)
        {
            if(k%j==0)
                cnt++;
        }
        ara[k]+=(cnt*2);
    }
}

int main()
{
    int tst, i, fnl[1001], n;
    scanf("%d", &tst);
    int l=2; fnl[1] = 1;
    square(ara);
    devisor(ara);
    for(j=2; j<=32; j++)
    {
        for(k=1000; k>=2; k--)
        {
            if(ara[k]==j)
            {
                fnl[l]=k;
                l++;
            }
        }
    }
    for(i=1; i<=tst; i++)
    {
        scanf("%d", &n);
        printf("Case %d: %d\n", i, fnl[n]);
    }
    return 0;
}

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.