ANITGUY4 - Editorial

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 cubes 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 t;
   	cin>>t;
   	while(t--){
   		ll ans=0;
   		int n;
   		cin>>n;
   		n--;
   		ans=2*((n*(n+1))/2)*((n*(n+1))/2);
   		n++;
   		ans+=(n*n*n);
   		cout<<ans<<"\n";
   	}
}