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;
}
Thanks for your solve...
ReplyDeleteCould you tell me,how you have written this law:
ReplyDeletesum = m*(n/2)??
suppose, m = 4 and n = 8, then the series is
Delete- 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)