Here you will find solutions of many problems on spoj. If you want solution of some problem which is not listed in blog or have doubt regarding any spoj problem (which i have solved) or any programming concept (data structure) you can mail me @ raj.nishant360@gmail.com

And my humble request to you all that don't copy the code only try to understand the logic and algorithm behind the code. I have started this because if you tried as hard as you can and still can't find any solution to the problem then you can refer to this.
You can read my answer how to start competitive programming CLICK HERE

Friday, February 21, 2014

CMIYC - Catch Me If You Can

CMIYC - Catch Me If You Can (link to the question)


It's easy one  So i'm gonna give the brief idea of it .
Let take some cases :
what if the n could be 3,4,5,6,7,8,9,10  ( 1,2 are already taken under sample example).
try to analyze the pattern . then you'll get 3,6,9, or in other words multiple of 3 as ON and rest as zero.
so the answer for the multiple of 3 would be (given number divided by 3) num/3 and rest are zero.

                                : :  : :  : :  : :  : :     : :  : :  : :  : :  : :  Here is your code  : :  : :  : :  : :  : :  : :    : :  : :  : :  : :  : :  : :

  
#include<stdio.h>

int main()
{
    int t; long long n;

    scanf("%i",&t);

    while(t--)
    {
        scanf("%lli",&n);

        (n%3) ? printf("0\n") : printf("%lld\n",n/3);
    }
    return 0;
}

No comments:

Post a Comment

Your comment is valuable to us