Squares in N*N Chessboard

PROBLEM :
Find total number of Squares in a N*N cheesboard.

Input:
The first line contains an integer T, depicting total number of test cases.
Then following T lines contains an integer N that is the side of the chessboard.


Output:
Each seperate line showing the maximum number of squares possible.


Constraints:
1 = T = 100
1 = N = 100


Example:
Input :
2
1
2

Output :
1
5

--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------

#include<iostream>
using namespace std;
long long Total_square(int ) ;
int main()
 {
int t,no ;
cin>>t ;
while(t--)
{
   cin>>no ;
   cout<<Total_square(no) ;
   cout<<endl ;
}
return 0;
}

long long Total_square(int no)
{
    long long count=0 ;
   
    while(no)
    {
        count=count+no*no ;
        no-- ;
    }
       
    return count ;
}

---------------------------------------------------------------------------------

Comments

Popular posts from this blog

Count ways to N'th Stair(Order does not matter)

Replace all ‘0’ with ‘5’ in an input Integer

Chocolate Distribution Problem

Remove characters from the first string which are present in the second string

Primality Test ( CodeChef Problem code: PRB01 )