Problem: Contest Page | CodeChef
DIFFICULTY:
EASY.
PROBLEM:
Chef has an old machine if the chef enters any natural number, the machine will display 1, 2, …n, n-1, n-2, n-3,…1 series and in next line prints sum of squares of each number in the series. Chef wants to create a computer program which can replicate the functionality of the machine. Help the chef to code.
Program:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int sum,t,n;
cin>>t;
while(t--){
cin>>n;
sum=0;
sum=n*n+(n*(n-1)*(2*n-1))/3;
cout<<sum<<endl;
}
}