Monday 11 January 2016

Solution of LIGHT OJ 1294 :: Positive Negative Sign


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>
int main()
{
    long long int m,n,a,b, sum, tst, i;
    scanf("%lld", &tst);
    for(i=1; i<=tst; i++)
    {
        scanf("%lld%lld", &n, &m);
        sum = m*(n/2);
        printf("Case %lld: %lld\n", i, sum);
    }
    return 0;
}

3 comments:

  1. Could you tell me,how you have written this law:
    sum = m*(n/2)??

    ReplyDelete
    Replies
    1. suppose, m = 4 and n = 8, then the series is
      - 1 - 2 -3 - 4 + 5 + 6 + 7 + 8
      now if you observe this series you get a pattern like following,
      - 1 + 5 = 4
      - 2 + 6 = 4
      - 3 + 7 = 4
      - 4 + 8 = 4
      I mean, the sum of an nth negative number and nth positive number is always 'm'.
      As the pair sum is 'm', so their will total n/2 pair and their sum is m*(n/2)

      Delete

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