SQUARE IT IS. Problem Code: ITGUY18


Can anyone help me how to solve this problem?

To make it easy to understand look at this image first

So ,The total for any NxN square is (N squared + N-1 squared + N-2 sqaured down to 1 when N=1.
so we need all the summation of all the sqaures 1 to N.

And For the Sum Of the First N Squares is
S = n(n+1)(2n+1)/6

[You read it about here. its just maths]

thats it .hope it helps.

My code

using namespace std;
typedef long long ll;

int main()
	ll t;
    	ll N,sum=0;
	sum=(N * (N + 1) * (2*N + 1)) / 6 ;//sum of n squares
return 0;

1 Like

Thanks, Bro.Got it.

i was thinking abt it …
thanks bro