**Problem: **

Richard Phillips Feynman was a well known American physicist and a recipient of the Nobel Prize in Physics. He worked in theoretical physics and also pioneered the field of quantum computing. He visited South America for ten months, giving lectures and enjoying life in the tropics. He is also known for his books “Surely You’re Joking, Mr. Feynman!” and “What Do You Care What Other People Think?”, which include some of his adventures below the equator.

His life-long addiction was solving and making puzzles, locks, and cyphers. Recently, an old farmer in South America, who was a host to the young physicist in 1949, found some papers and notes that is believed to have belonged to Feynman. Among notes about mesons and electromagnetism, there was a napkin where he wrote a simple puzzle: “how many different squares are there in a grid of *N* ×*N* squares?”.

Read full question here

**Hint:**

Try finding solution for 2×2 grid, 3×3 grid and 4×4 grid and come up with a sequence sum.

**Code: **

#include<iostream> using namespace std; int main(){ int n; do{ cin >> n; if(n == 0){ break; } long long unsigned int out = 0; int p = n; while(p > 0){ out += (p*p); p--; } cout << out << '\n'; }while(n!=0); return 0; }

**Explanation: **Well the algorithm is pretty intuitive, first you create squares of size 1×1 which are nothing but n^2 squares. Then you create 2×2 squares which are (n-1)^2 squares and so on you keep on adding till p != 0.