Problem Statement 4 :
Given n, find the sum of cubes of non-negative integers upto n.
Input :
First line specifies the number of test cases 't'. Following lines contain a single integer n.
Output:
In each line print the sum of cubes of non-negative integers upto n.
Constraints :
1<=t<=1000000
0<=n<=500
Time limit : 1s
Example test cases:
Input
5
0
4
2
3
5
Output
0
100
9
36
225
Solution:
#include<stdio.h>
int main()
{
int i,test,n;
scanf("%d",&test);
for( i=1;i<=test;i++)
{
scanf("%d",&n);
int sum=((n*(n+1)/2)*(n*(n+1)/2));
printf("%d\n",sum);
}
}
No comments:
Post a Comment