Dev Skill DCP-210: Gabu and the Series Solution
Problem Link
Dev Skill DCP-210: Gabu and the Series Solution
#include<stdio.h>
int main()
{
int m,n,i,j,t;
long long int b;
scanf("%d",&t);
j=0;
while(j<t)
{
scanf("%d",&n);
if(n==1)
printf("0\n");
else if(n==2)
printf("2\n");
else
{
b=2;
m=2;
for(i=3;i<=n;i++)
{
m=m+4;
b=b+m;
}
printf("%lld\n",b);
}
j++;
}
return 0;
}
No comments