×

CHESS1 - Editorial

Contest

Author: Md Shahid

Tester: Arkapravo Ghosh

Editorialist: Md Shahid

SIMPLE

PROBLEM:

Given N.You need to find the number of possible squares in N x N chess board.

EXPLANATION:

In this problem you have to count total numbers of all possible squares in the given $N X N$ grid chess.

Total number of square in $1 X 1$ chess = $1$.
Total number of square in $2 X 2$ chess = $5$.
Total number of square in $3 X 3$ chess = $14$.

Can you see a pattern in the above three lines?
Yes.

Total number of square in $1 X 1$ chess = $1$ = $1^2$.
Total number of square in $2 X 2$ chess = $5$ = $1^2$ $+$ $2^2$.
Total number of square in $3 X 3$ chess = $14$ = $1^2$ $+$ $2^2$ $+$ $3^2$.
$.$
$.$
$.$
Total number of squares in $N X N$ chess = $1^2$ $+$ $2^2$ $+$ $3^2$ $+$ $.$ $.$ $.$ $.$ $.$ $.$ $.$ $.$ $+$ $N^2$

As we know from algebra,

$1^2$ $+$ $2^2$ $+$ $3^2$ $+$ $.$ $.$ $.$ $.$ $.$ $.$ $.$ $.$ $+$ $N^2$ = $(N(N+1)(2N+1))/6$

Input N
Sum = (N(N+1)(2N+1))/6
print Sum


AUTHOR'S, TESTER'S AND EDITORIALIST'S SOLUTIONS:

Author's and editorialist’s solution can be found here. Tester's solution can be found here.

Tags:- ENCODING CHESS1 dshahid380

This question is marked "community wiki".

203
accept rate: 0%

19.6k349497539

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×620