MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

Spoj_problems/SAMER08F/solution.cpp:12–22  ·  view source on GitHub ↗

This method calculates no. of different squares in a given grid of N*N squares. The end of input is indicated by a line containing only one zero. This problem can also be solved using dp using eq => F(n) = n*2 + F(n-1) where F(1) = 1 However here we will use a simple formula. i.e., Sum of Squares = n*(n+1)*(2n+1)/6 */

Source from the content-addressed store, hash-verified

10 i.e., Sum of Squares = n*(n+1)*(2n+1)/6
11*/
12int main()
13{
14 jaadu;
15 int n;
16 cin>>n;
17 while(n!= 0){
18 cout<<(n)*(n+1)*(2*n + 1)/6<<endl;
19 cin>>n;
20 }
21 return 0;
22}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected