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 */
| 10 | i.e., Sum of Squares = n*(n+1)*(2n+1)/6 |
| 11 | */ |
| 12 | int 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected