Formula for n*n Grid's square sum :{ n*(n+1)*(2n+1) }/6
Formula for n*m Grid's Rectangle sum : { n*(n+1) /2 }^2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Author : Shohan | |
/// URI 1323 | |
/// Problem level : Easy | |
#include<stdio.h> | |
int main() | |
{ | |
int ans,n,t; | |
while(scanf("%d",&n)==1){ | |
if(n==0) | |
break; | |
ans=(n*(n+1)) * (2*n+1); | |
t=ans/6; | |
printf("%d\n",t); | |
} | |
return 0; | |
} |