Given two Boxes A & B, for every N {where N means 1,2,3,....N} the values to be added in the boxes is sum of values in A & B in (N-1).
For example: if N = 1, Box A has (1)
Box B has (1)
so, total = value in box 1 + value in box 2
= 1 + 1
= 2
Let us consider, N=2:
So, for N=1, we already have total = 2. This total value is the value which we should add in each of the box.
So, Total = value in box 1 + value in box 2
= {1+2} + {1+2}
= 3 + 3
= 6
Method 1:
Implementation:
Input
The first line - number of test case T.
Each of the next T lines - Number N
Output
Output the total at N
Sample Input2
1
2
Sample Output2
6
Method 2:
Here is another code which has a less time complexity and runs fine for all the test cases.
Implementation:
For example: if N = 1, Box A has (1)
Box B has (1)
so, total = value in box 1 + value in box 2
= 1 + 1
= 2
Let us consider, N=2:
So, for N=1, we already have total = 2. This total value is the value which we should add in each of the box.
So, Total = value in box 1 + value in box 2
= {1+2} + {1+2}
= 3 + 3
= 6
Method 1:
Implementation:
#include <stdio.h>
int main()
{
     int t,N,choco,v,p;
     scanf("%d",&t);
     while(t--)
     {
          choco=2;
          scanf("%d",&N);
          if(N==1)
          printf("%d\n",choco);
          else
          {
               for(v=2,p=2;v<=N;v++,p++)
               {
                    choco=choco+v+p;
               }
               printf("%d\n",choco);
          }
     }
     return 0;
}
Input
The first line - number of test case T.
Each of the next T lines - Number N
Output
Output the total at N
Sample Input2
1
2
Sample Output2
6
Method 2:
Here is another code which has a less time complexity and runs fine for all the test cases.
Implementation:
#include 
int main()
{
      unsigned long long int t,N;
      scanf("%llu",&t);
      while(t--)
      {
           scanf("%llu",&N);
           printf("%llu\n",(N*(N+1)));
      }
      return 0;
}