Saturday, 26 March 2016

Solution of LIGHT OJ 1116 :: Ekka Dokka


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 main()
{
    long long int m, n, w;
    long long int tst, i, j, odd, Valid, limit;
    scanf("%lld", &tst);
    for(i=1; i<=tst; i++)
    {
        scanf("%lld", &w);
        limit = w/2;
        Valid = 0;
        odd = 0;
        for(j=2; j <= limit;  j *= 2)
        {
            if(w%j == 0)
                odd = w/j;
            if(odd%2 == 1)
            {
                Valid = 1;
                break;
            }
        }
        if(Valid==1)
            printf("Case %lld: %lld %lld\n", i, odd, j);
        else
            printf("Case %lld: Impossible\n", i);
    }
    return 0;
}

1 comment:

  1. #include
    #include
    int main()
    {
    int j,i,x,n;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {

    scanf("%d",&x);
    if(x%2==0)
    {
    for(j=2;j<=x/2;j=j+2)
    {
    if(x%j==0&&((x/j)%2==1))
    {
    printf("Case %d: %d %d\n",i,x/j,j);
    break;
    }

    }
    }
    else
    printf("Case %d: Impossible\n",i);
    }
    return 0;
    }
    can you please help me to find where my mistake is

    ReplyDelete

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