Thursday, June 23, 2016

SOLUTION OF URI 1158


//  1158   (Mahmud_Jamil) BRUR
//  Sum of Consecutive Odd Numbers III




#include <stdio.h>
int main()
{
    int N, X, Y, a, b, c, d, e;
    scanf("%d", &N);
    for(a=1; a<=N; a++)
    {
        scanf("%d %d", &X, &Y);
        if(X%2==1)
        {
            c=0;
            for(b=1; b<=Y; b++)
            {
                c+=X;
                X+=2;
            }
            printf("%d\n", c);
        }
        else
        {
            X++;
            c=0;
            for(b=1; b<=Y; b++)
            {
                c+=X;
                X+=2;
            }
            printf("%d\n", c);
        }
    }
    return 0;
}





0 comments:

Post a Comment