SUM of all integers

Description:

"Yesterday, puppy Tuzik learned a magically efficient method to find the sum of the integers from 1 to N. He denotes it as sum(N). But today, as a true explorer, he defined his own new function: sum(D, N), which means the operation sum applied D times: the first time to N, and each subsequent time to the result of the previous operation. For example, if D = 2 and N = 3, then sum(2, 3) equals to sum(sum(3)) = sum(1 + 2 + 3) = sum(6) = 21. Tuzik wants to calculate some values of the sum(D, N) function. Will you help him with that? " Test Case 1 Input (stdin) 2 1 4 2 3 Expected Output 10 21 Test Case 2 Input (stdin) 1 1 5 Expected Output 15

Program :


#include<stdio.h>

int main()

{

    long long int t,d,n;

    scanf("%lld",&t);

    while(t--)

    {

        scanf("%lld %lld",&d,&n);

        while(d--)

        {

            n=(n*(n+1))/2;

        }

        printf("%lld\n",n);

    }

    return 0;

}